Class Calendar
- All Implemented Interfaces:
Animation, Editable, ActionSource, StyleListener, Iterable<Component>
Date widget for selecting a date/time value.
To localize strings for month names use the values "Calendar.Month" using the
3 first characters of the month name in the resource localization e.g.
"Calendar.Jan", "Calendar.Feb" etc...
To localize strings for day names use the values "Calendar.Day" in the
resource localization e.g. "Calendar.Sunday",
"Calendar.Monday" etc...
Note that we recommend using the com.codename1.ui.spinner.Picker
class which is superior when running on the device for most use cases.
Form hi = new Form("Calendar", new BorderLayout());
Calendar cld = new Calendar();
cld.addActionListener((e) -> Log.p("You picked: " + new Date(cld.getSelectedDay())));
hi.add(BorderLayout.CENTER, cld);
-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
ConstructorsConstructorDescriptionCalendar()Constructs a calendar with the current date and timeCalendar(long time) Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention)Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention)Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention)Constructs a calendar with the current date and time with left and right images set -
Method Summary
Modifier and TypeMethodDescriptionvoidFires when a change is made to the month view of this componentvoidAllows tracking selection changes in the calendar in real timevoidAllows tracking selection changes in the calendar in real timevoidAdds an ActionListener to the day buttons.voidFires when a new month is selectedprotected voidbindDayListener(Component cmp, ActionListener l) Since a day may be any component type, developers should override this method to add support for binding the click listener to the given component.protected ButtonThis method creates the Day Button Component for the Month Viewprotected ComponentCreates a day within the Calendar, this method is protected allowing Calendar to be subclassed to replace the rendering logic of individual day buttons.protected LabelcreateDayTitle(int day) This method creates the Day title Component for the Month ViewReturns the currently viewed date (as opposed to the selected date)getDate()Return the date object matching the current selectionprotected StringgetDayText(Component cmp) Since a day may be any component type, developers should override this method to add support for removing the click listener from the given component.Gets the selected style of the month view component within the calendarGets the un selected style of the month view component within the calendarlongReturns the time for the current calendar.Gets the dates selected on the calendar or null if no date is selectedReturns
Gets the Calendar timezonevoidhighlightDate(Date date, String uiid) Highlights a date on the calendar using the supplied uiid.voidhighlightDates(Collection<Date> dates, String uiid) Highlights dates on the calendar using the supplied uiid.booleanThis flag determines if selected date can be changed by selecting an alternative datebooleanIf true multiple days can be selected on a calendar and "getSelectedDays()" will return the dates selectedbooleanWhen set to true days will be rendered as 2 digits with 0 preceding single digit daysvoidFires when a change is made to the month view of this componentvoidAllows tracking selection changes in the calendar in real timevoidAllows tracking selection changes in the calendar in real timevoidRemoves ActionListener from day buttonsvoidFires when a new month is selectedvoidsetChangesSelectedDateEnabled(boolean changesSelectedDateEnabled) This flag determines if selected date can be changed by selecting an alternative datevoidSets the Calendar view on the given date, only the the month and year are being considered.voidSets the current date in the view and the selected date to be the same.protected voidsetDayEnabled(Component cmp, boolean enable) Since a day may be any component type, developers should override this method to add support for enabling or disabling the right component.protected voidsetDayText(Component cmp, String text) Since a day may be any component type, developers should override this method to add support for setting the displayed string.protected voidsetDayUIID(Component cmp, String uiid) Since a day may be any component type, developers should override this method to add support for setting the right component's UIID.voidSets the selected style of the month view component within the calendarvoidSets the un selected style of the month view component within the calendarvoidsetMultipleSelectionEnabled(boolean multipleSelectionEnabled) When set to true multiple days can be selected on a calendar and "getSelectedDays()" will return the dates selectedvoidThis method sets the Calendar selected dayvoidsetSelectedDays(Collection<Date> selectedDays) Sets the dates to be selected on the calendarvoidsetSelectedDays(Collection<Date> selectedDays, String uiid) Sets the dates to be selected on the calendar with a custom uiid.voidsetSelectedDaysUIID(String uiid) Sets the selectedDays UIID to the given uiid.voidsetTimeZone(TimeZone tmz) Sets the Calendar timezone, if not specified Calendar will use the default timezonevoidsetTwoDigitMode(boolean twoDigitMode) When set to true days will be rendered as 2 digits with 0 preceding single digit daysvoidsetYearRange(int minYear, int maxYear) Sets the Calendar min and max yearsvoidunHighlightDate(Date date) Un-highlights dates on the calendar by removing the highlighting uiid.voidunHighlightDates(Collection<Date> dates) Un-highlights dates on the calendar by removing the highlighting uiid.protected voidupdateButtonDayDate(Button dayButton, int currentMonth, int day) This method updates the Button day.protected voidupdateButtonDayDate(Button dayButton, int year, int currentMonth, int day) This method updates the Button day.protected voidupdateButtonDayDate(Component dayButton, int currentMonth, int day) This method updates the Button day.protected voidupdateButtonDayDate(Component dayButton, int year, int currentMonth, int day) This method updates the Button day.Methods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
Calendar
public Calendar(long time) Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention)
Parameters
time: time since epoch
-
Calendar
public Calendar()Constructs a calendar with the current date and time -
Calendar
Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention)
Parameters
-
time: time since epoch -
tmz: a reference timezone
-
-
Calendar
-
Calendar
Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention)
Parameters
-
time: time since epoch -
tmz: a reference timezone -
leftArrowImage: an image for calendar left arrow -
rightArrowImage: an image for calendar right arrow
-
-
-
Method Details
-
getSelectedDay
public long getSelectedDay()Returns the time for the current calendar.
Returns
the time for the current calendar.
-
getDate
Return the date object matching the current selection
Returns
the date object matching the current selection
-
setDate
Sets the current date in the view and the selected date to be the same.
Parameters
d: new date
-
setYearRange
public void setYearRange(int minYear, int maxYear) Sets the Calendar min and max years
Parameters
-
minYear: the min year -
maxYear: the max year
-
-
setSelectedDate
This method sets the Calendar selected day
Parameters
d: the selected day
-
getCurrentDate
Returns the currently viewed date (as opposed to the selected date)
Returns
the currently viewed date
-
setCurrentDate
Sets the Calendar view on the given date, only the the month and year are being considered.
Parameters
d: the date to set the calendar view on.
-
getTimeZone
Gets the Calendar timezone
Returns
Calendar TimeZone
-
setTimeZone
Sets the Calendar timezone, if not specified Calendar will use the default timezone
Parameters
tmz: the timezone
-
getMonthViewSelectedStyle
Gets the selected style of the month view component within the calendar
Returns
the style of the month view
-
setMonthViewSelectedStyle
Sets the selected style of the month view component within the calendar
Parameters
s: style for the month view
-
getMonthViewUnSelectedStyle
Gets the un selected style of the month view component within the calendar
Returns
the style of the month view
-
setMonthViewUnSelectedStyle
Sets the un selected style of the month view component within the calendar
Parameters
s: style for the month view
-
addActionListener
Fires when a change is made to the month view of this component
Parameters
l: listener to add
- Specified by:
addActionListenerin interfaceActionSource
-
removeActionListener
Fires when a change is made to the month view of this component
Parameters
l: listener to remove
- Specified by:
removeActionListenerin interfaceActionSource
-
addMonthChangedListener
Fires when a new month is selected
Parameters
l: listener to add
-
removeMonthChangedListener
Fires when a new month is selected
Parameters
l: listener to remove
-
addDayActionListener
Adds an ActionListener to the day buttons. This is different from
Calendar.addActionListenerand will only fire when an active day is selected.Parameters
l: listener to add
-
removeDayActionListener
Removes ActionListener from day buttons
Parameters
l: listener to remove
-
addDataChangedListener
Allows tracking selection changes in the calendar in real time
Parameters
l: listener to add
-
removeDataChangedListener
Allows tracking selection changes in the calendar in real time
Parameters
l: listener to remove
-
addDataChangeListener
Allows tracking selection changes in the calendar in real time
Parameters
l: listener to add
Deprecated
use #addDataChangedListener(DataChangedListener) instead
-
removeDataChangeListener
Allows tracking selection changes in the calendar in real time
Parameters
l: listener to remove
Deprecated
use #removeDataChangedListener(DataChangedListener) instead
-
isChangesSelectedDateEnabled
public boolean isChangesSelectedDateEnabled()This flag determines if selected date can be changed by selecting an alternative date
Returns
true if enabled
-
setChangesSelectedDateEnabled
public void setChangesSelectedDateEnabled(boolean changesSelectedDateEnabled) This flag determines if selected date can be changed by selecting an alternative date
Parameters
changesSelectedDateEnabled: @param changesSelectedDateEnabled if true pressing on a date will cause the selected date to be changed to the pressed one
-
createDay
This method creates the Day Button Component for the Month View
Returns
a Button that corresponds to the Days Components
Deprecated
override
createDayComponent()instead -
createDayTitle
This method creates the Day title Component for the Month View
Parameters
day: the relevant day values are 0-6 where 0 is Sunday.
Returns
a Label that corresponds to the relevant Day
-
updateButtonDayDate
This method updates the Button day.
Parameters
-
dayButton: the button to be updated -
year: the current year -
currentMonth: the current month -
day: the new button day
-
-
updateButtonDayDate
This method updates the Button day.
Parameters
-
dayButton: the button to be updated -
currentMonth: the current month -
day: the new button day
-
-
updateButtonDayDate
This method updates the Button day.
Parameters
-
dayButton: the button to be updated -
year: the current year -
currentMonth: the current month -
day: the new button day
Deprecated
override the method that accepts a generic component
-
-
updateButtonDayDate
This method updates the Button day.
Parameters
-
dayButton: the button to be updated -
currentMonth: the current month -
day: the new button day
Deprecated
override the method that accepts a generic component
-
-
isTwoDigitMode
public boolean isTwoDigitMode()When set to true days will be rendered as 2 digits with 0 preceding single digit days
Returns
the twoDigitMode
-
setTwoDigitMode
public void setTwoDigitMode(boolean twoDigitMode) When set to true days will be rendered as 2 digits with 0 preceding single digit days
Parameters
twoDigitMode: the twoDigitMode to set
-
getSelectedDays
Gets the dates selected on the calendar or null if no date is selected
Returns
the selected days
-
setSelectedDays
Sets the dates to be selected on the calendar
Parameters
selectedDays: the multipleDateSelection to set
-
setSelectedDays
Sets the dates to be selected on the calendar with a custom uiid. To use default uiid "
CalendarMultipleDay", call this method without the "uiidparameter"Parameters
-
selectedDays: the multipleDateSelection to set -
uiid: a custom uiid to be used in the dates selected
-
-
getSelectedDaysUIID
Returns
selectedDays uiid
-
setSelectedDaysUIID
Sets the selectedDays UIID to the given uiid. being considered.
Parameters
uiid: the uiid to change to
-
highlightDate
-
highlightDates
Highlights dates on the calendar using the supplied uiid. (Selected dates uiid takes precedence over highlighted dates uiid)
Parameters
-
dates: the dates to be highlighted -
uiid: a custom uiid to be used in highlighting the dates
-
-
unHighlightDates
Un-highlights dates on the calendar by removing the highlighting uiid. (
selectedDaysUIIDuiid will be applied to any of the dates that are part ofselectedDays)Parameters
dates: the dates to be un-highlighted
-
unHighlightDate
Un-highlights dates on the calendar by removing the highlighting uiid. (
selectedDaysUIIDuiid will be applied to the date if it is part ofselectedDays)Parameters
date: the date to be un-highlighted
-
isMultipleSelectionEnabled
public boolean isMultipleSelectionEnabled()If true multiple days can be selected on a calendar and "
getSelectedDays()" will return the dates selectedReturns
the multipleSelectionEnabled
-
setMultipleSelectionEnabled
public void setMultipleSelectionEnabled(boolean multipleSelectionEnabled) When set to true multiple days can be selected on a calendar and "
getSelectedDays()" will return the dates selectedParameters
multipleSelectionEnabled: the multipleSelectionEnabled to set
-
createDayComponent
Creates a day within the Calendar, this method is protected allowing Calendar to be subclassed to replace the rendering logic of individual day buttons.
Returns
a button representing the day within the Calendar
-
bindDayListener
Since a day may be any component type, developers should override this method to add support for binding the click listener to the given component.
Parameters
-
l: listener interface -
cmp: day component returned by createDayComponent()
-
-
setDayText
-
getDayText
-
setDayUIID
-
setDayEnabled
Since a day may be any component type, developers should override this method to add support for enabling or disabling the right component.
Parameters
-
cmp: day component returned by createDayComponent() -
enable: the text set the component to
-
-