I have a JSlider
, range 1 to 60. I have the ticks labeled every 10, starting at 10. My code for the slider is this:
JSlider slider = new JSlider(1, 60);
slider.setValue(20);
slider.setMajorTickSpacing(10);
slider.setMinorTickSpacing(1);
slider.setLabelTable(slider.createStandardLabels(10, 10));
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setSnapToTicks(true);
The behavior is basically what would be expected, looking at the code; it creates a slider with the given range, sets the value to 20, spaces major ticks at 1, 11, 21, etc., labels at 10, 20, 30, etc. However, I want the major ticks to line up with the labels at 10, 20, 30, etc., but there is no method setMajorTickSpacing(int spacing, int start)
.
Is there any workaround to do something equivalent to createStandardLabels(10, 10)
with setMajorTickSpacing
so that the major ticks line up with the labels?
Edit: My problem is with the ticks, not the labels. I want ticks created incrementally every 1 tick, major ticks (not labels) created every multiple of 10 starting on 10. Unlike Java Slider - how to make custom ticks? this tick pattern is uniform, simply not starting at the slider's minimum. If I understand correctly, setLabelTable
only allows the changing of labels, not unlabeled ticks.