在JSlider中,
Knob是小滑块
Track是slider中间小滑块滑动的轨迹:JSlider.setPaintTrack(false)
用到的方向常量:都是SwingConstants的,虽然可以用如JSlider.VERTICAL,但也能用
SwingConstants.VERTICAL, RIGHT, HORIZONTAL, LEFT, CENTER.
Tick mark是slider中的刻度数字:JSlider.setPaintTicks(true)与
JSlider.setMajorTickSpacing(int)和setMinorTickSpacing(int)一起用
显示滑动标尺上的数字:JSlider.setPaintLabels(true)
// Create horizontal slider
JSlider slider = new JSlider();
// Register a change listener
slider.addChangeListener(new ChangeListener() {
// This method is called whenever the slider's value is changed
public void stateChanged(ChangeEvent evt) {
JSlider slider = (JSlider)evt.getSource();
if (!slider.getValueIsAdjusting()) {
// Get new value
int value = slider.getValue();
}
}
});