// 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();
}
}
});
Related Examples |