Package com.github.lgooddatepicker.components

# Class DateTimePicker

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.github.lgooddatepicker.components.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:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class javax.swing.JPanel

`JPanel.AccessibleJPanel`

## Nested classes/interfaces inherited from class javax.swing.JComponent

`JComponent.AccessibleJComponent`

## Nested classes/interfaces inherited from class java.awt.Container

`Container.AccessibleAWTContainer`

## Nested classes/interfaces inherited from class java.awt.Component

`Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy`

## Field Summary

Fields
Modifier and Type
Field
Description
`DatePicker`
`datePicker`
datePicker, This holds the date picker component of this DateTimePicker.
`TimePicker`
`timePicker`
timePicker, This holds the time picker component of this DateTimePicker.

### Fields inherited from class javax.swing.JComponent

`listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW`

### Fields inherited from class java.awt.Component

`accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

### Fields inherited from interface java.awt.image.ImageObserver

`ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

## Constructor Summary

Constructors
Constructor
Description
`DateTimePicker()`
Constructor with default settings.
`DateTimePicker(DatePickerSettings datePickerSettingsOrNull, TimePickerSettings timePickerSettingsOrNull)`
Constructor with custom settings.

## Method Summary

Modifier and Type
Method
Description
`void`
`addDateTimeChangeListener(DateTimeChangeListener listener)`
addDateTimeChangeListener, This adds a change listener to this DateTimePicker.
`void`
`clear()`
clear, This will clear the date picker text and the time picker text.
`int`
`getBaseline(int width, int height)`
getBaseline, This returns the baseline value of the dateTextField of the date picker.
`DatePicker`
`getDatePicker()`
getDatePicker, This returns the date picker component of this DateTimePicker.
`ArrayList<DateTimeChangeListener>`
`getDateTimeChangeListeners()`
getDateTimeChangeListeners, This returns a new ArrayList, that contains any change listeners that are registered with this DateTimePicker.
`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.
`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.
`TimePicker`
`getTimePicker()`
getTimePicker, This returns the time picker component of this DateTimePicker.
`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.
`boolean`
`isEnabled()`
isEnabled, Returns true if this component is enabled, otherwise returns false.
`void`
`removeDateTimeChangeListener(DateTimeChangeListener listener)`
removeDateTimeChangeListener, This removes the specified change listener from this DateTimePicker.
`void`
`setDateTimePermissive(LocalDateTime optionalDateTime)`
setDateTimePermissive, This uses the supplied LocalDateTime to set the value of the DatePicker and the TimePicker.
`void`
`setDateTimeStrict(LocalDateTime optionalDateTime)`
setDateTimeStrict, This uses the supplied LocalDateTime to set the value of the DatePicker and the TimePicker.
`void`
`setEnabled(boolean enabled)`
setEnabled, This enables or disables the DateTimePicker.
`void`
`setGapSize(int gapSize, ConstantSize.Unit units)`
setGapSize, This sets the size of the gap between the date picker and the time picker.
`String`
`toString()`
toString, This method is identical to the function toStringPermissive().
`String`
`toStringPermissive()`
toStringPermissive, This returns a string representation of the values which are currently stored in the date and time picker.
`String`
`toStringStrict()`
toStringStrict, This returns a string representation of the values which are currently stored in the date and time picker.

### Methods inherited from class javax.swing.JPanel

`getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI`

### Methods inherited from class javax.swing.JComponent

`addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update`

### Methods inherited from class java.awt.Container

`add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree`

### Methods inherited from class java.awt.Component

`action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## 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.