Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove text above JSlider

Tags:

java

swing

I have a JSlider in my GUI that goes from 0 to 100. For some 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?

like image 719
z - Avatar asked Sep 20 '10 19:09

z -


2 Answers

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());
like image 98
BCarpe Avatar answered Oct 29 '22 22:10

BCarpe


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.

like image 35
Etaoin Avatar answered Oct 29 '22 22:10

Etaoin