Class DateTimePicker

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class DateTimePicker extends JPanel
DateTimePicker, This class combines a date picker with a time picker. This class provides functionality for creating and manipulating the two components as a single unit. This class also provides functions for getting or setting the combined date and time as a java.time.LocalDateTime object. This class is implemented as a relatively thin wrapper around the DatePicker and TimePicker instances. Those instances can be accessed with the getDatePicker() and getTimePicker() functions. There are a small number of customizable settings that apply specifically to the DateTimePicker class. Each of those settings is contained inside the TimePickerSettings class, and begin with the prefix "zDateTimePicker_". For information on how to use or customize the DatePicker and TimePicker classes, see the javadocs for those two classes. You can create an instance of DateTimePicker using the default constructor, which will create a DatePicker and a TimePicker that has default settings and uses the default locale. Alternatively, you can supply a DatePickerSettings instance and/or a TimePickerSettings instance when you construct this class.
See Also:
  • Field Details

    • datePicker

      public DatePicker datePicker
      datePicker, This holds the date picker component of this DateTimePicker.
    • timePicker

      public TimePicker timePicker
      timePicker, This holds the time picker component of this DateTimePicker.
  • Constructor Details

    • DateTimePicker

      public DateTimePicker()
      Constructor with default settings. This creates a new instance of DateTimePicker, with default DatePicker and TimePicker settings, in the default locale.
    • DateTimePicker

      public DateTimePicker(DatePickerSettings datePickerSettingsOrNull, TimePickerSettings timePickerSettingsOrNull)
      Constructor with custom settings. This creates a new instance of DateTimePicker, with the supplied DatePicker and TimePicker settings.
  • Method Details

    • addDateTimeChangeListener

      public void addDateTimeChangeListener(DateTimeChangeListener listener)
      addDateTimeChangeListener, This adds a change listener to this DateTimePicker. For additional details, see the DateTimeChangeListener class documentation.
    • clear

      public void clear()
      clear, This will clear the date picker text and the time picker text. If the date picker and time picker are set to allow empty values, then the last valid date and last valid time will also be cleared. If the date picker, the time picker, or both are set to disallow empty values, then the last valid value for those components will not be changed by this function.
    • getBaseline

      public int getBaseline(int width, int height)
      getBaseline, This returns the baseline value of the dateTextField of the date picker.
      Overrides:
      getBaseline in class JComponent
    • getDatePicker

      public DatePicker getDatePicker()
      getDatePicker, This returns the date picker component of this DateTimePicker.
    • removeDateTimeChangeListener

      public void removeDateTimeChangeListener(DateTimeChangeListener listener)
      removeDateTimeChangeListener, This removes the specified change listener from this DateTimePicker.
    • getDateTimeChangeListeners

      public ArrayList<DateTimeChangeListener> getDateTimeChangeListeners()
      getDateTimeChangeListeners, This returns a new ArrayList, that contains any change listeners that are registered with this DateTimePicker.
    • getDateTimePermissive

      public LocalDateTime getDateTimePermissive()
      getDateTimePermissive, This attempts to retrieve the date from the date picker, and the time from the time picker, and return a single LocalDateTime value. If a date is present but the time picker contains null, then the time portion of the returned value will be set to LocalTime.MIDNIGHT. This will return null if the date picker contains null (an empty value). This can return null if "allowEmptyDates" is true for the date picker. If allowEmptyDates is false for the date picker, then this can never return null. Note: If the automatic validation of the date picker text or the time picker text has not yet occurred, then the value returned from this function may not always match the current text. See the DatePicker.getDate() and TimePicker.getTime() functions for additional details.
    • getDateTimeStrict

      public LocalDateTime getDateTimeStrict()
      getDateTimeStrict, This attempts to retrieve the date from the date picker, and the time from the time picker, and return a single LocalDateTime value. If a date is present but the time picker contains null, then this will return null. This will return null if the date picker contains null (an empty value). This can return null if "allowEmptyDates" is true for the date picker. If allowEmptyDates is false for the date picker, then this can never return null. Note: If the automatic validation of the date picker text or the time picker text has not yet occurred, then the value returned from this function may not always match the current text. See the DatePicker.getDate() and TimePicker.getTime() functions for additional details.
    • getTimePicker

      public TimePicker getTimePicker()
      getTimePicker, This returns the time picker component of this DateTimePicker.
    • isDateTimeAllowed

      public boolean isDateTimeAllowed(LocalDateTime value)
      isDateTimeAllowed, This checks to see if the specified value is allowed by any currently set veto policies and "allowEmptyValues" settings of both the DatePicker and TimePicker components. If the specified value would be allowed by both components, then this returns true. If the specified value would not be allowed by either or both components, then this returns false. For additional details, see: DatePicker.isDateAllowed() and TimePicker.isTimeAllowed().
    • isEnabled

      public boolean isEnabled()
      isEnabled, Returns true if this component is enabled, otherwise returns false.
      Overrides:
      isEnabled in class Component
    • setDateTimePermissive

      public void setDateTimePermissive(LocalDateTime optionalDateTime)
      setDateTimePermissive, This uses the supplied LocalDateTime to set the value of the DatePicker and the TimePicker. Values that are set from this function are processed through the same validation procedures as values that are typed by the user. Note: The functions setDateTimePermissive(LocalDateTime value) and setDateTimeStrict(LocalDateTime value) are identical (Only the "get" version of these functions is different), but both of these function names are included for API consistency and for compatibility with JavaBeans data binding functionality. More specifically: Date validation and time validation are performed separately. Date validation is handled by the DatePicker, and time validation is handled by the TimePicker. The veto policy and "allowEmptyValues" settings are used to determine whether or not a particular value is "allowed". Allowed values will be set in the text field, and also committed to the "last valid value" of the applicable component. Disallowed values will be set in the text field (with a disallowed indicator font), but will not be committed to the "last valid value" of the applicable component. It is possible for a particular LocalDateTime value to be allowed by one component (and therefore committed to that component), but not allowed by the other component. A value can be checked against any current veto policies, and against the allowEmptyTimes settings, by calling isDateTimeAllowed(). This can be used to determine (in advance), if a particular value would be allowed by both components. Note: If empty values are allowed by both components, and there is no veto policy on either component, then all possible values will (always) be allowed. These are the default settings of the components. For additional details about the automatic date and time validation, see: DatePicker.setDate() and TimePicker.setTime().
    • setDateTimeStrict

      public void setDateTimeStrict(LocalDateTime optionalDateTime)
      setDateTimeStrict, This uses the supplied LocalDateTime to set the value of the DatePicker and the TimePicker. Note: The functions setDateTimePermissive(LocalDateTime value) and setDateTimeStrict(LocalDateTime value) are identical (Only the "get" version of these functions is different), but both of these function names are included for API consistency and for compatibility with JavaBeans data binding functionality. See setDateTimePermissive() for the full Javadocs for this function.
    • setEnabled

      public void setEnabled(boolean enabled)
      setEnabled, This enables or disables the DateTimePicker. When the component is enabled, dates and times can be selected by the user using any methods that are allowed by the current settings. When the component is disabled, there is no way for the user to interact with the components. More specifically, dates and times cannot be selected with the mouse, or with the keyboard, and the date and time pickers change their color scheme to indicate the disabled state. Any currently stored text and last valid values are retained while the component is disabled.
      Overrides:
      setEnabled in class JComponent
    • setGapSize

      public void setGapSize(int gapSize, ConstantSize.Unit units)
      setGapSize, This sets the size of the gap between the date picker and the time picker.
    • toString

      public String toString()
      toString, This method is identical to the function toStringPermissive(). This returns a string representation of the values which are currently stored in the date and time picker. If the last valid value of the date picker is null, then this will return an empty string (""). If the last valid value of the time picker is null, then that portion of the time will be replaced with LocalTime.MIDNIGHT. Javadocs from LocalDateTime.toString(): Outputs this date-time as a String, such as 2007-12-03T10:15:30.

      The output will be one of the following ISO-8601 formats:

      • uuuu-MM-dd'T'HH:mm
      • uuuu-MM-dd'T'HH:mm:ss
      • uuuu-MM-dd'T'HH:mm:ss.SSS
      • uuuu-MM-dd'T'HH:mm:ss.SSSSSS
      • uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS
      The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.
      Overrides:
      toString in class Component
    • toStringPermissive

      public String toStringPermissive()
      toStringPermissive, This returns a string representation of the values which are currently stored in the date and time picker. If the last valid value of the date picker is null, then this will return an empty string (""). If the last valid value of the time picker is null, then that portion of the time will be replaced with LocalTime.MIDNIGHT. Javadocs from LocalDateTime.toString(): Outputs this date-time as a String, such as 2007-12-03T10:15:30.

      The output will be one of the following ISO-8601 formats:

      • uuuu-MM-dd'T'HH:mm
      • uuuu-MM-dd'T'HH:mm:ss
      • uuuu-MM-dd'T'HH:mm:ss.SSS
      • uuuu-MM-dd'T'HH:mm:ss.SSSSSS
      • uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS
      The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.
    • toStringStrict

      public String toStringStrict()
      toStringStrict, This returns a string representation of the values which are currently stored in the date and time picker. If the last valid value of the date picker or the time picker is null, then this will return an empty string (""). Javadocs from LocalDateTime.toString(): Outputs this date-time as a String, such as 2007-12-03T10:15:30.

      The output will be one of the following ISO-8601 formats:

      • uuuu-MM-dd'T'HH:mm
      • uuuu-MM-dd'T'HH:mm:ss
      • uuuu-MM-dd'T'HH:mm:ss.SSS
      • uuuu-MM-dd'T'HH:mm:ss.SSSSSS
      • uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS
      The format used will be the shortest that outputs the full value of the time where the omitted parts are implied to be zero.