I have a slider and it's max value is 60. How to show only 10, 25 and 60 as a label ?

Thanks in Advance!

有帮助吗?

解决方案

With the setLabelTable method. Copy-paste from the tutorial:

//Create the slider
JSlider framesPerSecond = new JSlider(JSlider.VERTICAL,
                                      FPS_MIN, FPS_MAX, FPS_INIT);
...

//Create the label table
Hashtable labelTable = new Hashtable();
labelTable.put( new Integer( 0 ), new JLabel("Stop") );
labelTable.put( new Integer( FPS_MAX/10 ), new JLabel("Slow") );
labelTable.put( new Integer( FPS_MAX ), new JLabel("Fast") );
framesPerSecond.setLabelTable( labelTable );

framesPerSecond.setPaintLabels(true);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top