Java JSpinner set Date value

Description

Java JSpinner set Date value

import java.awt.FlowLayout;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;

public class Main extends JFrame {
   public Main() {
      super("java2s.com");

      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setLayout(new FlowLayout());

      SpinnerDateModel dateModel = new SpinnerDateModel();
      JSpinner spinner = new JSpinner(dateModel);

      Calendar calendar = new GregorianCalendar(2000, Calendar.JANUARY, 1);
      spinner.setValue(calendar.getTime());
      //from w w w  . ja va  2  s.  com
      getContentPane().add(spinner);
   }

   public static void main(String[] args) {
      Main frame = new Main();
      frame.pack();
      frame.setVisible(true);
   }
}



PreviousNext

Related