JSpinner: addChangeListener(ChangeListener lis) : JSpinner « javax.swing « Java by API






JSpinner: addChangeListener(ChangeListener lis)

 
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class MainClass {

  public static void main(final String args[]) {
    JFrame frame = new JFrame("JSpinner Dates");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ChangeListener listener = new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        System.out.println("Source: " + e.getSource());
      }
    };

    SpinnerModel model3 = new SpinnerNumberModel();
    JSpinner spinner3 = new JSpinner(model3);
    spinner3.addChangeListener(listener);

    frame.add(spinner3, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);

  }

}

           
         
  








Related examples in the same category

1.new JSpinner.DateEditor(JSpinner spinner, String dateFormatPattern)
2.JSpinner.NumberEditor.NumberEditor(JSpinner spinner)
3.new JSpinner(SpinnerModel model2)
4.new JSpinner(SpinnerModel model1) (SpinnerDateModel)
5.JSpinner: getModel()
6.JSpinner: setEditor(JComponent editor)
7.JSpinner: setValue(Object value)