问题描述
如何为 JSlider
配置拇指大小?
使用默认值,以及 JSlider
的范围为256,拇指只有几个像素宽,这使得用鼠标控制变得非常困难。
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.
我使用Windows 7的外观和滑块看起来像这样:
I am using the Windows 7 look and feel and the slider looks like this:
启用 paintTicks
的主要和次要tick spacing of 0给出了一个更好的(虽然不是首选)显示:
Enabling paintTicks
with a major and minor tick spacing of 0 gives a better (although not preferred) display:
所需的显示如下图所示 - 取自本机Windows 7应用程序:
The desired display is shown in the following image - taken from a native Windows 7 application:
推荐答案
您可以尝试自定义 JSl ider
外观如下:
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
参考:
- Customizing a JSlider Look and Feel
请注意,这些更改将适用于所有 JSlider
实例,这可能是使这种做法不受欢迎。
It's important to note that these changes will apply to all JSlider
instances, which may make this approach undesirable.
这篇关于设置JSlider拇指的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!