Search code examples
javaswingjlabeljslider

Java JSlider with two set of labels


Is it possible to display two set of labels with the same ticks on JSlider, one on top, one on bottom?


Solution

  • You can implement your own SliderUI, as shown here, and override paintTicks().

    image

    Alternatively, you may be trying to represent alternate units, such as Celsius v. Kelvin. You might want to consider one of these options:

    • Add an adjacent toggle button to switch the displayed tick units.

    • Add a second JSlider and let each one's ChangeListener set the other's model to the equivalent setting.