Class CalendarPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.github.lgooddatepicker.components.CalendarPanel
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
CalendarPanel,
This implements a swing component that displays and draws a calendar. The CalendarPanel has
controls for changing the current month or year, and for selecting dates.
In most cases, you will not need to create your own instances of CalendarPanel. The DatePicker
class automatically creates its own instances of CalendarPanel whenever the user clicks on the
"toggle calendar" button. However, the CalendarPanel can also (optionally) be used as an
independent component when desired.
The Life cycle of CalendarPanel inside a DatePicker: Each time that the user clicks the toggle
calendar button on a date picker, a new CalendarPanel instance is created and displayed, within
of a new instance of CustomPopup. The calendar panel instance is closed and disposed each time
that the date picker popup is closed.
- See Also:
-
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 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
ConstructorsConstructorDescriptionConstructor, Independent CalendarPanel with default settings.CalendarPanel
(DatePicker parentDatePicker) Constructor, Private CalendarPanel For DatePicker.CalendarPanel
(DatePickerSettings settings) Constructor, Independent CalendarPanel with supplied settings. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCalendarListener
(CalendarListener listener) addCalendarListener, This adds a calendar listener to this calendar panel.void
drawCalendar, This can be called to redraw the calendar.getCalendarListeners, This returns a new ArrayList, that contains any calendar listeners that are registered with this CalendarPanel.getDisplayedYearMonth, This returns the year and month that is currently displayed in the calendar.getSelectedDate, This returns the date that is currently marked as "selected" in the calendar.getSettings, This returns the calendar panel settings instance.void
removeCalendarListener
(CalendarListener listener) removeCalendarListener, This removes the specified calendar listener from this CalendarPanel.void
setDisplayedYearMonth
(YearMonth yearMonth) setDisplayedYearMonth, This sets the year and month that is currently displayed in the calendar.void
setLocale, The locale for a CalendarPanel should generally be set in the DatePickerSettings.void
setSelectedDate
(LocalDate selectedDate) setSelectedDate, This sets a date that will be marked as "selected" in the calendar, and sets the displayed YearMonth to show that date.void
setSelectedDateWithoutShowing
(LocalDate selectedDate) setSelectedDateWithoutShowing, This sets a date that will be marked as "selected" in the calendar.void
setSettings
(DatePickerSettings datePickerSettings) setSettings, This will set the settings instance for this calendar panel.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, getBaseline, 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, setEnabled, 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, isEnabled, 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, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
CalendarPanel
public CalendarPanel()Constructor, Independent CalendarPanel with default settings. This creates an independent calendar panel with a default set of DatePickerSettings. The calendar panel will use the default operating system locale and language. -
CalendarPanel
Constructor, Independent CalendarPanel with supplied settings. This creates This creates an independent calendar panel with the supplied date picker settings. If the datePickerSettings are null, then a default settings instance will be created and applied to the CalendarPanel. -
CalendarPanel
Constructor, Private CalendarPanel For DatePicker. Important Note: This function is only intended to be called from the DatePicker class. This creates a calendar panel from an existing DatePicker, for internal usage by that DatePicker instance. This will use the settings from the DatePicker instance. Technical note: This constructor is only called from the DatePicker.openPopup() function. A new CalendarPanel is created every time the popup is opened. Therefore, any DatePickerSettings variables that are initialized in this constructor are automatically able to correctly handle being set either before or after, a DatePicker is constructed.
-
-
Method Details
-
addCalendarListener
addCalendarListener, This adds a calendar listener to this calendar panel. For additional details, see the CalendarListener class documentation. -
drawCalendar
public void drawCalendar()drawCalendar, This can be called to redraw the calendar. The calendar will be drawn with the currently displayed year and month. This function should not normally need to be called by the programmer, because the calendar will automatically redraw itself as needed. -
getCalendarListeners
getCalendarListeners, This returns a new ArrayList, that contains any calendar listeners that are registered with this CalendarPanel. -
getDisplayedYearMonth
getDisplayedYearMonth, This returns the year and month that is currently displayed in the calendar. This will never return null. Note that this is -not- the same as the displayed selected date, and the displayed selected date may or may not be inside the displayedYearMonth. It is expected that this function will be rarely needed by developers. -
getSelectedDate
getSelectedDate, This returns the date that is currently marked as "selected" in the calendar. If no date is selected, then this will return null. This should not be confused with the "last valid date" of a DatePicker object. This function would typically only be needed when the CalendarPanel class is being used independently from the DatePicker class. -
getSettings
getSettings, This returns the calendar panel settings instance. -
removeCalendarListener
removeCalendarListener, This removes the specified calendar listener from this CalendarPanel. -
setSelectedDate
setSelectedDate, This sets a date that will be marked as "selected" in the calendar, and sets the displayed YearMonth to show that date. If the supplied date is null, then the selected date will be cleared, and the displayed YearMonth will be set to today's year and month. Technical note: This is implemented with the following two functions: setSelectedDateWithoutShowing() and setSelectedYearMonth(). -
setSelectedDateWithoutShowing
setSelectedDateWithoutShowing, This sets a date that will be marked as "selected" in the calendar. The selectedDate will only be visible when the matching YearMonth is being displayed in the calendar. Note that this function does -not- change the currently displayed YearMonth. (This function does not "show" the YearMonth for the supplied date.) -
setDisplayedYearMonth
setDisplayedYearMonth, This sets the year and month that is currently displayed in the calendar. The yearMonth can not be set to null. If the parameter is null, an exception will be thrown. Note that this function does -not- change the displayed selected date. -
setLocale
setLocale, The locale for a CalendarPanel should generally be set in the DatePickerSettings. This function only exists to avoid confusion with the swing function Component.setLocale(). This forwards any function calls to: CalendarPanel.getSettings().setLocale(). For the complete Javadocs, see DatePickerSettings.setLocale(). -
setSettings
setSettings, This will set the settings instance for this calendar panel. The previous settings will be deleted. Note that calling this function effectively re-initializes the picker component. All aspects of the component will be changed to match the provided settings. Any currently selected date will not be changed by this function. -
getPreviousYearButton
-
getPreviousMonthButton
-
getNextMonthButton
-
getNextYearButton
-