List of usage examples for javax.swing SpinnerDateModel setStart
public void setStart(Comparable<Date> start)
From source file:net.sf.housekeeper.swing.util.BoundComponentFactory.java
/** * Creates a JSpinner whose value is bound to the given ValueModel. This * means, that the value of the spinner and the value of the ValueModel are * synchronized bidirectionally. Additionally, the spinner uses * the current locale's short format for displaying a date. * //from w w w. j av a 2 s .c o m * @param valueModel the model that provides the value. Must not be null and * must provide {@link Date}objects. * @return A spinner whose value is bound to <code>valueModel</code>. */ public static JSpinner createDateSpinner(final ValueModel valueModel) { assert valueModel != null : "Parameter valueModel must not be null"; assert valueModel.getValue().getClass() .equals(Date.class) : "valueModel must provide Date objects as values"; final SpinnerDateModel model = new SpinnerDateModelAdapter(valueModel); //Need to truncate the current date for correct spinner operation model.setStart(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); model.setCalendarField(Calendar.DAY_OF_MONTH); final JSpinner spinner = new JSpinner(model); //Set the spinner's editor to use the current locale's short date // format final SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT); final String formatPattern = dateFormat.toPattern(); spinner.setEditor(new JSpinner.DateEditor(spinner, formatPattern)); return spinner; }
From source file:net.sf.housekeeper.swing.FoodEditorView.java
/** * Creates a JSpinner which uses the current locale's short format for * displaying a date. It's default date date is set to today's date. * //from w w w . j ava 2 s . com * @return The created spinner. */ private JSpinner createDateSpinner() { final SpinnerDateModel model = new SpinnerDateModel(); //Need to truncate the current date for correct spinner operation model.setStart(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); model.setCalendarField(Calendar.DAY_OF_MONTH); final JSpinner spinner = new JSpinner(model); //Set the spinner's editor to use the current locale's short date // format final SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT); final String formatPattern = dateFormat.toPattern(); spinner.setEditor(new JSpinner.DateEditor(spinner, formatPattern)); return spinner; }