I'm having trouble using the JSlider class - especially with tick marks.
The first time I use setMajorTickSpacing and setMinorTickSpacing , everything works as expected. However, subsequent calls to setMajorTickSpacing update ticks, but not tags. I wrote a simple example demonstrating this behavior:
import java.awt.event.*; import javax.swing.*; public class SliderTest { public static void main(String args[]) { JFrame frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); frame.setSize(300, 250); JSlider slider = new JSlider(0, 100, 0); slider.setMajorTickSpacing(10); slider.setMinorTickSpacing(1); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setMajorTickSpacing(25); slider.setMinorTickSpacing(5); frame.add(slider); frame.pack(); frame.setVisible(true); } }
There seems to be a problem with two simple tasks - either with slider.setLabelTable(null) or slider.setLabelTable(slider.createStandardLabels(25)) before the second call to setMajorTickSpacing . Given this, it seems that the shortcut table is not updating correctly.
I am not sure if this is the intended behavior or not. My first instinct is that updating tick intervals should also update labels, but there are also arguments to separate the two.
So, I would like to know what it is - is this a bug in JSlider or the intended behavior? If this is the intended behavior, what will be the outstanding reasons for choosing?
java user-interface swing jslider
charlemagne
source share