Java Swing Range Slider UI

I need a slider with two knobs on it (representing a range), and I found this one great here . However, they created their own UI that extends Java BasicSliderUI . They override the drawing method to draw their own pens. I would like to use the default handles based on the current look. I tried calling the BasicSliderUI paintThumb method, but this gives me a general pen that does not seem to be attached to the current view and Feel. As far as I can tell, JSlider gets its UI from MultiSliderUI . How can I create a UI that changes as a JSlider but draws two buttons instead of one?

Thanks in advance!

+4
source share
3 answers

SwingX provides the JXMultiThumbSlider , which may be what you are looking for.

+4
source

Try to get the current look and feel of javax.swing.UIManager and name getUI(new JSlider()) on it. This should return the current user interface used for JSlider , which should be closed before JSliderUI .

Unfortunately, JSliderUI does not have a paintThumb(Graphics g) method, but BasicSliderUI does, and at least on Windows XP and Windows Vista, the appearance of the system is a subclass of BasicSliderUI , as is the Metal appearance.

So, as soon as you have JSliderUI , see if it is an instance of BasicSliderUI , so you can direct it to BasicSliderUI and use paintThumb(Graphics g) on it, otherwise the default is to use the way you do it already. I don’t know if this actually works, but it would be my first attempt if I needed it.

I don't have Linux or Mac to check the source if their JSliderUI also derived from BasicSliderUI , but if you do, check the java source code.

+2
source

You can use the RangeSlider class from Jide Commons Level

It is open source.

+1
source

All Articles