I have this situation (JSlider Showing Values when is not required). And I don't want to show the current Value on JSlider.
The next images shown running the code on Windows 10, Cent OS 7, and MacOS Sierra
Here my code:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class JSliderLAF {
public static void changeLAF(Container container, String laf) {
try {
UIManager.setLookAndFeel(laf);
} catch (ClassNotFoundException | InstantiationException |
IllegalAccessException | UnsupportedLookAndFeelException e) {
}
SwingUtilities.updateComponentTreeUI(container);
}
public static void main(String args[]) {
EventQueue.invokeLater(() -> {
JPanel jpVert = new JPanel();
jpVert.setLayout(new BoxLayout(jpVert, BoxLayout.PAGE_AXIS));
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
JSlider jsl = new JSlider();
jsl.setMajorTickSpacing(20);
jsl.setMinorTickSpacing(5);
jsl.setPaintLabels(true);
jsl.setPaintTicks(true);
jsl.setSnapToTicks(true);
JPanel jpHorz = new JPanel();
jpHorz.setLayout(new BoxLayout(jpHorz, BoxLayout.LINE_AXIS));
JLabel jlName = new JLabel(info.getName() + " : ");
JLabel jlClass = new JLabel(info.getClassName());
jpHorz.add(jsl);
jpHorz.add(Box.createRigidArea(new Dimension(5,0)));
jpHorz.add(jlName);
jpHorz.add(Box.createRigidArea(new Dimension(2,0)));
jpHorz.add(jlClass);
jpHorz.add(Box.createRigidArea(new Dimension(2,0)));
jpHorz.add(Box.createHorizontalGlue());
changeLAF(jsl,info.getClassName());
jpVert.add(jpHorz);
}
final JFrame frame = new JFrame();
frame.add(jpVert, BorderLayout.NORTH);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
});
}
}
public static void changeLAF(Container container, String laf) {
try {
UIManager.setLookAndFeel(laf);
UIManager.put("Slider.paintValue", false);
} catch (ClassNotFoundException | InstantiationException |
IllegalAccessException | UnsupportedLookAndFeelException e) {
}
SwingUtilities.updateComponentTreeUI(container);
}