Java Swing How to - Set value to Date JSpinner








Question

We would like to know how to set value to Date JSpinner.

Answer

// w w  w .ja v a2s.  co m
import java.util.Calendar;
import java.util.GregorianCalendar;

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

public class Main {
  public static void main(String[] argv) throws Exception {
    SpinnerDateModel dateModel = new SpinnerDateModel();
    JSpinner spinner = new JSpinner(dateModel);

    Calendar calendar = new GregorianCalendar(2000, Calendar.JANUARY, 1);
    spinner.setValue(calendar.getTime());
  }
}