开发者

Java Swing - Drawing markers on JSlider

开发者 https://www.devze.com 2022-12-23 04:39 出处:网络
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

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 开发者_Python百科of each marker? Or perhaps a better way of performing this task?

Many Thanks!


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消