Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can the size of the thumb be configured for a JSlider?

With the defaults, and a range for the JSlider of 256, the thumb is only a few pixels wide, which makes it quite difficult to control with a mouse.

I am using the Windows 7 look and feel and the slider looks like this:

Screenshot of slider

Enabling paintTicks with a major and minor tick spacing of 0 gives a better (although not preferred) display:

Screenshot of slider with paintTicks enabled

The desired display is shown in the following image - taken from a native Windows 7 application:

Screenshot of native slider

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
376 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could try customizing the JSlider Look and Feel as follows:

UIDefaults defaults = UIManager.getDefaults();
defaults.put("Slider.thumbHeight", HEIGHT_AS_INTEGER); // change height
defaults.put("Slider.thumbWidth", WIDTH_AS_INTEGER); // change width

Reference:

It's important to note that these changes will apply to all JSlider instances, which may make this approach undesirable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...