import java.time.LocalDate; import java.time.chrono.Chronology; import java.time.format.DateTimeFormatter; package javafx.scene.control; /** * The DatePicker control allows the user to enter a date as text or * to select a date from a calendar popup. The calendar is based on * either the standard ISO-8601 chronology or any of the other * chronology classes defined in the java.time.chrono package. * *
The {@link #valueProperty() value} property represents the * currently selected {@link java.time.LocalDate}. An initial date can * be set via the {@link #DatePicker(java.time.LocalDate) constructor} * or by calling {@link #setValue(java.time.LocalDate) setValue()}. The * default value is null. * *
* final DatePicker datePicker = new DatePicker();
* datePicker.setOnAction(new EventHandler() {
* public void handle(Event t) {
* LocalDate date = datePicker.getValue();
* System.err.println("Selected date: " + date);
* }
* });
*
*
* The {@link #chronologyProperty() chronology} property specifies a
* calendar system to be used for parsing, displaying, and choosing
* dates.
* The {@link #valueProperty() value} property is always defined in
* the ISO calendar system, however, so applications based on a
* different chronology may use the conversion methods provided in the
* {@link java.time.chrono.Chronology} API to get or set the
* corresponding {@link java.time.chrono.ChronoLocalDate} value. For
* example:
*
*
* LocalDate isoDate = datePicker.getValue();
* ChronoLocalDate chronoDate =
* ((isoDate != null) ? datePicker.getChronology().date(isoDate) : null);
* System.err.println("Selected date: " + chronoDate);
*
*
*
* @since 8.0
*/
public class DatePicker extends ComboBoxBase
* final Callback dayCellFactory = new Callback() {
* public DateCell call(final DatePicker datePicker) {
* return new DateCell() {
* @Override public void updateItem(LocalDate item, boolean empty) {
* super.updateItem(item, empty);
*
* if (MonthDay.from(item).equals(MonthDay.of(9, 25))) {
* setTooltip(new Tooltip("Happy Birthday!"));
* setStyle("-fx-background-color: #ff4444;");
* }
* if (item.equals(LocalDate.now().plusDays(1))) {
* // Tomorrow is too soon.
* setDisable(true);
* }
* }
* };
* }
* };
* datePicker.setDayCellFactory(dayCellFactory);
*
*/
public final void setDayCellFactory(CallbackThe default value is returned from a call to
* {@code Chronology.ofLocale(Locale.getDefault(Locale.Category.FORMAT))}.
* The default is usually {@link java.time.chrono.IsoChronology} unless
* provided explicitly in the {@link java.util.Locale} by use of a
* Locale calendar extension.
*/
public ObjectProperty The default value is false unless otherwise defined in a
* resource bundle for the current locale.
*
* This property may be toggled by the end user by using a
* context menu in the DatePicker popup, so it is recommended that
* applications save and restore the value between sessions.
*/
public final BooleanProperty showWeekNumbersProperty();
public final void setShowWeekNumbers(boolean value);
public final boolean isShowWeekNumbers();
/**
* Converts the input text to an object of type LocalDate and vice
* versa.
*
* If not set by the application, the DatePicker skin class will
* set a converter based on a {@link java.time.DateTimeFormatter}
* for the current {@link java.util.Locale} and
* {@link #chronologyProperty() chronology}. This formatter is
* then used to parse and display the current date value.
*
* Example using an explicit formatter:
* Example that wraps the default formatter and catches parse exceptions:
*
*
* datePicker.setConverter(new StringConverter
*
* @see javafx.scene.control.ComboBox#converterProperty
*/
public ObjectProperty
* final StringConverter