访问 Swing JSlider 的拇指/手柄/旋钮
基本上我想显示运动时滑块手柄指向的当前值(通过鼠标或键盘)。我可以通过添加新的 ChangeListener & 轻松获取当前值。重写 stateChanged 方法。但我似乎无法获取手柄的当前位置。
我可以硬着头皮在固定的地方创建一个标签。不断更新它,但我想显示手柄上方(或下方)的值。
Basically I want to display the current value pointed to by the slider handle when in motion (either via mouse or keyboard). I can easily get the current value by adding a new ChangeListener & overriding stateChanged method. But I cant seem to get the current location of the handle.
I can just bite the bullet and create a label at a constant place & update it continuously but I want to display the value just above (or below) the handle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是一个好的或非常灵活的解决方案,但也许您可以实现自己的
SliderUI
。例如,使用已经定义的BasicUI
,您可以访问包含您需要的值的thumbRect
字段。Not an good or very flexible solution but maybe you can implement your own
SliderUI
. E.g. using the already definedBasicUI
you can access the fieldthumbRect
which contains the values you need.如果Nimbus 外观和感觉是一个选项,那么一个实时可以在相关 UI 默认值中指定值的显示:
If the Nimbus Look and Feel is an option, a live display of the value can be specified in the relevant UI default: