开发者

How to remove text above JSlider

I have a JSlider in my GUI that goes from 0 to 100. For s开发者_运维问答ome reason, there is text above the slider position that displays the current value of the slider and it follows my slider around. I.e., if I move my slider halfway, "50" appears above where my slider currently is. However, I can't figure out what that text field is called, all I know is its part of the slider.

I want to either remove it or be able to change it to something else, how would I do that?


I would have just commented on Etaoin's answer, but I don't have the reputation for it yet.

At any rate, call this before instantiating the JSlider:

UIManager.put("Slider.paintValue", false);

Note the capital 'V' in paintValue.

Furthermore, to print all of the fun things that are currently set by your UIManager, enter this code anywhere after the UIManager has been instantiated:

Iterator<Entry<Object, Object>> it = UIManager.getDefaults().entrySet().iterator();
while(it.hasNext())
    System.out.println(it.next());


This bothered me on a project once, and I found the following workaround. Call this once before instantiating your JSlider -- I put it in a static block in my JPanel subclass:

UIManager.put("Slider.paintValue", false);

That'll take care of it.


Do you mean a tooltip? Is it a little box that appears over the slider control and follows your mouse around if you grab the slider? If this is the case, you can disable it simply by calling setToolTipText( null ), or override the text with setToolTipText( "My Text" ).


As I see there is a setLabelTable method in JSlider with a Dictionary parameter. I have not used it but I guess that if you set it to an empty dictionary (or empty labels for every possible value) then no labels will appear.

A better solution is the usage of setPaintLabels with a false value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜