Java Swing - 在 JSlider 上绘制标记

发布于 2024-08-24 12:17:58 字数 379 浏览 10 评论 0原文

我有一个进度条,它继承自 JSlider 以提供突出显示功能。 突出显示可以添加到滑块的某个点(和颜色),然后将它们绘制到控件上。如下:

http://img101.imageshack.us/img101/7608/sliderexample.png

问题是我无法将突出显示放在正确的位置,它们需要与标记位于同一位置。我也不知道如何检索标记开始和结束位置的左右边距。

有没有办法获取每个标记的坐标?或者也许是执行此任务的更好方法?

非常感谢!

I have a progress bar which inherits from JSlider to provide highlighting functionality. Highlights can be added to the slider at a point (and a Color) and these are then painted onto the control. As follows:

http://img101.imageshack.us/img101/7608/sliderexample.png

The problem is that I cannot get the highlights in the right place, they need to be in the same location as the markers. I also do not know how to retrieve the left and right margins to where the markers start and end.

Is there anyway to get the coordinates of each marker? Or perhaps a better way of performing this task?

Many Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以往的大感动 2024-08-31 12:17:58

这取决于外观和外观。感觉当用户使用一些非标准的 L&F 时,很有可能根本没有任何标记。事实上,您的问题既是功能扩展又是图形实现,因此您可能必须同时接触 JSlider 和 SliderUI。

请注意以下方法:

javax.swing.JSlider.getMajorTickSpacing() 
javax.swing.JSlider.getMinorTickSpacing() 

此外,研究 javax.swing.plaf.SliderUI 及其扩展类可能会有所帮助,尤其是

javax.swing.plaf.basic.BasicSliderUI.paintTicks(java.awt.Graphics)
javax.swing.plaf.basic.BasicSliderUI.xPositionForValue(int)

This is dependent on the Look & Feel and there's a good chance that there aren't any markers at all when the user uses some non-standard L&F. In fact, your problem is both an extension of functionality and graphic realization so you may have to touch both, JSlider and SliderUI.

Note the following methods:

javax.swing.JSlider.getMajorTickSpacing() 
javax.swing.JSlider.getMinorTickSpacing() 

Also, it may help to look into javax.swing.plaf.SliderUI and the classes extending it, especially

javax.swing.plaf.basic.BasicSliderUI.paintTicks(java.awt.Graphics)
javax.swing.plaf.basic.BasicSliderUI.xPositionForValue(int)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文