Java Swing Range Slider U.I
Asked Answered
P

3

5

I needed a slider with two knobs on it (representing a range) and I found this nifty one here. However, they created their own U.I. which extends Java's BasicSliderUI. They override the paint method to draw their own knobs. I would like to use the default knobs based on the current look and feel. I tried calling BasicSliderUI's paintThumb method, but this gives me a generic looking knob which doesn't seem to be tied to the current look and feel. As far as I can tell, JSlider gets its U.I. from MultiSliderUI. How can I create a U.I which changes like JSlider's, but draws two knobs instead of one?

Thanks in advance!

Professed answered 16/7, 2009 at 21:5 Comment(2)
Hey, now feel free to post the links. I'm too lazy to do it myself.Kiakiah
P.S. sorry about that restriction. It is there to prevent link spammers.Kiakiah
G
5

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

Grampus answered 16/7, 2009 at 22:32 Comment(0)
L
2

Try getting the current look and feel from the javax.swing.UIManager and calling getUI(new JSlider()) on it. This should return the current UI used for the JSlider, which should be castable to JSliderUI.

Unfortunately JSliderUI doesn't have a paintThumb(Graphics g) method, but the BasicSliderUI does, and at least on Windows XP and Windows Vista the system look and feel is a subclass of BasicSliderUI, so is the Metal look and feel.

So once you have the JSliderUI see if it is an instance of BasicSliderUI, if so you can cast it to BasicSliderUI and use the paintThumb(Graphics g) on it, otherwise default to the way you are doing 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 JSliderUIs are derived from BasicSliderUI as well, but if you do then check out the java source code.

Lordsandladies answered 22/7, 2009 at 10:33 Comment(0)
A
1

You can use RangeSlider class from Jide Commons Layer

This is opensource.

Anthropomorphosis answered 19/7, 2009 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.