如何在Java中创建JSlider,设置工具提示文本(帮助文本),间距,字体

・1 分钟阅读

如何在Java中创建JSlider,设置工具提示文本(帮助文本),间距,字体和其他JSlider属性:




// at the top of the class
private JSlider volumeSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);

// later in the code ...
private void configureVolumeSliderControl() {
    volumeSlider.setToolTipText(\"Volume control\");
    volumeSlider.addChangeListener(controller);
    volumeSlider.setMajorTickSpacing(10);
    volumeSlider.setMinorTickSpacing(1);
    volumeSlider.setPaintTicks(true);
    volumeSlider.setPaintLabels(true);
    volumeSlider.setBorder(BorderFactory.createEmptyBorder(0,0,10,0));
    Font font = new Font(\"Serif\", Font.ITALIC, 15);
    volumeSlider.setFont(font);
}


Xn_warm profile image