Java Swing How to - Install DateEdtior JSpinner








Question

We would like to know how to install DateEdtior JSpinner.

Answer

import java.awt.BorderLayout;
/*w  ww.j a va2 s.  c  o m*/
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;


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


    SpinnerModel model = new SpinnerDateModel();
    JSpinner spinner = new JSpinner(model);
    JComponent editor = new JSpinner.DateEditor(spinner);
    spinner.setEditor(editor);

    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(spinner, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.SOUTH);

 

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