Changing the Placement of Major Ticks on a JSlider
843805Apr 25 2007 — edited Apr 26 2007I have a JSlider with a minimum value of 2, a maximum value of 50 and a major tick increment of 5. Creating the slider with those options alone results in major ticks and labels at 2, 7, 12, ..., but I want 2, 5, 10, ... . I can use a label table to get the labels to be 2, 5, 10, ..., but the major ticks are still at 2, 7, 12, ... . Is there any way to get the major ticks to line up with the labels?
The only thing I thought of is a hack to create a slider from 0 to 48 with reverse orientation (so 0 is on the right) and then use custom labels to display 50 where the value is really 0 and 2 where the value is really 48. Then I would need to translate the user's value by subtracting it from 50. It seems really ugly to have a slider whose values don't correspond to the values the user is actually controlling, though, so I'm hoping there's a better way.
I am required to use Java 1.5.