绘制JSlider的滑块图标
想要重新绘制 JSlider
的标记或拇指,而不是标准灰色。我怎样才能实现这个目标?
Would like to repaint the the marker or the thumb of the JSlider
instead of the standard gray. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
扩展
BasicSliderUI
委托并非没有危险,但它确实允许对渲染进行任意控制,如下面的示例所示。Extending the
BasicSliderUI
delegate is not without peril, but it does allow arbitrary control over the rendering, as suggested in the example below.有三种方法:
首选方法< /code>
使用 Synth 的示例
SynthSliderTest.java
demo.xml
文件There are three ways:
Preferred of Ways
Example using Synth
SynthSliderTest.java
demo.xml
file扩展 TrashGod 非常有用的答案,我添加了几行代码,以允许该栏填充到您移动它的位置。该栏的其余部分将为空白:
执行此操作的代码是:
如果您还想要背景颜色,请在绘制第一个矩形之前绘制第二个矩形:
Expanding on TrashGod's very helpful answer, I added in a few lines of code to allow the bar to be filled up to the point in which you have moved it. The rest of the bar will be blank:
The code to do this is:
And if you want a background color as well, paint a second rectange before you paint the first: