ting today if we are in a hurry calendar.setTime(new Date()); picker.getMonthView().setLowerBound(calendar.getTime()); // end of next week CalendarUtils.endOfWeek(calendar); calendar.add(Calendar.WEEK_OF_YEAR); picker.getMonthView().setUpperBound(calendar.getTime()); Similar to a JXMonthView, the JXDatePicker fires an ActionEvent when the user actively commits or cancels a selection. Interested client code can add a ActionListener to be notified by the user action.
JXDatePicker picker = new JXDatePicker(new Date()); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent e) { if (JXDatePicker.COMMIT_KEY.equals(e.getActionCommand)) { saveDate(picker.getDate()); } } }; picker.addActionListener(l);
Note that ActionListener will
not be notified if the user edits the date text without hitting the Enter key afterwards. To detect both kinds of date change, interested client code can add a PropertyChangeListener.
JXDatePicker picker = new JXDatePicker(new Date()); PropertyChangeListener listener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if ("date".equals(e.getPropertyName()) { saveDate(picker.getDate()); } } }; picker.addPropertyChangeListener(listener);
The DateFormats used in the JXDatePicker's are initialized to the default formats of the DatePickerFormatter, as defined by the picker's resourceBundle DatePicker.properties. Application code can overwrite the picker's default
picker.setDateFormats(myCustomFormat, myAlternativeCustomFormat);
PENDING JW: explain what the alternatives are for (after understanding it myself ;-)
The selected Date is a bound property of the JXDatePicker. This allows easy binding to a property of a custom bean when using a binding framework.
Keybindings (as installed by the UI-Delegate)
- ENTER commits the edited or selected value
- ESCAPE reverts the edited or selected value
- alt-DOWN opens the monthView popup
- shift-F5 if monthView is visible, navigates the monthView to today (no effect otherwise)
- F5 commits today
PENDNG JW: support per-OS keybindings to be installed, currently they are hardcoded in our (single) BasicDatePickerUI.
@author Joshua Outwater
@author Jeanette Winzenburg
@see JXMonthView
@see org.jdesktop.swingx.calendar.DateSelectionModel
@see DatePickerFormatter