new SpinnerDateModel(Date value, Comparable start, Comparable end, int calendarField)
import java.awt.BorderLayout;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("JSpinner Dates");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Calendar cal = Calendar.getInstance();
Date now = cal.getTime();
cal.add(Calendar.YEAR, -50);
Date startDate = cal.getTime();
cal.add(Calendar.YEAR, 100);
Date endDate = cal.getTime();
SpinnerModel model2 = new SpinnerDateModel(now, startDate, endDate, Calendar.YEAR);
JSpinner spinner2 = new JSpinner(model2);
JLabel label2 = new JLabel("Range");
JPanel panel2 = new JPanel(new BorderLayout());
panel2.add(label2, BorderLayout.WEST);
panel2.add(spinner2, BorderLayout.CENTER);
frame.add(panel2, BorderLayout.SOUTH);
frame.setSize(200, 90);
frame.setVisible(true);
}
}
Related examples in the same category