Java by API/javax.swing/SpinnerDateModel
Версия от 17:43, 31 мая 2010; (обсуждение)
new SpinnerDateModel()
import java.awt.BorderLayout;
import java.text.DateFormatSymbols;
import java.util.Locale;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerModel;
public class MainClass {
public static void main(String args[]) {
JFrame f = new JFrame("JSpinner Sample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH);
String days[] = symbols.getWeekdays();
SpinnerModel model1 = new SpinnerListModel(days);
SpinnerModel model2 = new SpinnerDateModel();
JSpinner spinner1 = new JSpinner(model1);
JSpinner spinner2 = new JSpinner(model2);
f.add(spinner1, BorderLayout.NORTH);
f.add(spinner2, BorderLayout.SOUTH);
f.setSize(300, 100);
f.setVisible(true);
}
}
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);
}
}