// Create a nummber spinner
JSpinner spinner = new JSpinner();
// Add the listener
spinner.addChangeListener(new SpinnerListener());
// Changing the value programmatically also fires an event
spinner.setValue(new Integer(100));
public class SpinnerListener implements ChangeListener {
public void stateChanged(ChangeEvent evt) {
JSpinner spinner = (JSpinner)evt.getSource();
// Get the new value
Object value = spinner.getValue();
}
}
Related Examples |