Java SpinnerModel get from JSpinner

Description

Java SpinnerModel get from JSpinner


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

public class Main {

  public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JSpinner dateSpinner = new JSpinner();

    dateSpinner.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        SpinnerModel dateModel = dateSpinner.getModel();
        System.out.println(dateModel.getValue());
      }/*from   w ww.  jav  a  2 s . com*/
    });
    frame.add(dateSpinner,"North");

    frame.setSize(300, 200);
    frame.setVisible(true);
  }

}



PreviousNext

Related