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

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

java - Set the size of a JSlider thumb

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...