Java Swing Range 滑块 UI
我需要一个带有两个旋钮的滑块(代表一个范围),我在这里找到了这个漂亮的滑块。 然而,他们创建了自己的 UI,扩展了 Java 的 基本SliderUI。 他们重写paint方法来绘制自己的旋钮。 我想使用基于当前外观和感觉的默认旋钮。 我尝试调用 BasicSliderUI 的 paintThumb 方法,但这给了我一个通用的外观旋钮,它似乎与当前的外观和感觉无关。 据我所知, JSlider 从 获取其 UI多滑块UI。 如何创建一个像 JSlider 一样更改的 UI 的,但是画了两个旋钮而不是一个?
提前致谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 RangeSlider 类
Jide Commons Layer
这是开源的。
You can use RangeSlider class from
Jide Commons Layer
This is opensource.
尝试从
javax.swing.UIManager
获取当前外观并对其调用getUI(new JSlider())
。 这应该返回用于JSlider
的当前 UI,它应该可以转换为JSliderUI
。不幸的是,
JSliderUI
没有paintThumb(Graphics g)
方法,但BasicSliderUI
有,并且至少在 Windows XP 和 Windows Vista 上系统外观是 BasicSliderUI 的子类,Metal 外观也是如此。因此,一旦您拥有
JSliderUI
,请查看它是否是BasicSliderUI
的实例,如果是,您可以将其转换为BasicSliderUI
并使用其上的paintThumb(Graphics g)
,否则默认为您已经执行的方式。 我不知道这是否真的有效,但如果我需要的话,这将是我的第一次尝试。我没有 Linux 或 Mac 来检查其
JSliderUI
是否也源自BasicSliderUI
的源代码,但如果您这样做,请查看 java 源代码。Try getting the current look and feel from the
javax.swing.UIManager
and callinggetUI(new JSlider())
on it. This should return the current UI used for theJSlider
, which should be castable toJSliderUI
.Unfortunately
JSliderUI
doesn't have apaintThumb(Graphics g)
method, but theBasicSliderUI
does, and at least on Windows XP and Windows Vista the system look and feel is a subclass ofBasicSliderUI
, so is the Metal look and feel.So once you have the
JSliderUI
see if it is an instance ofBasicSliderUI
, if so you can cast it toBasicSliderUI
and use thepaintThumb(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
JSliderUI
s are derived fromBasicSliderUI
as well, but if you do then check out the java source code.SwingX 提供JXMultiThumbSlider 这可能就是您正在寻找的。
SwingX provides JXMultiThumbSlider which may be what you are looking for.