public class Calendar
ImplementsActionSource, Animation, Editable, Iterable<Component>, StyleListener
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);
Constructors
public Calendar(long time) | Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention) |
public Calendar() | Constructs a calendar with the current date and time |
public Calendar(long time, TimeZone tmz) | Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention) |
public Calendar(Image leftArrowImage, Image rightArrowImage) | Constructs a calendar with the current date and time with left and right images set |
public Calendar(long time, TimeZone tmz, Image leftArrowImage, Image rightArrowImage) | Creates a new instance of Calendar set to the given date based on time since epoch (the Date convention) |
Methods
public long getSelectedDay() | Returns the time for the current calendar. |
public Date getDate() | Return the date object matching the current selection |
public void setDate(Date d) | Sets the current date in the view and the selected date to be the same. |
public void setYearRange(int minYear, int maxYear) | Sets the Calendar min and max years |
public void setSelectedDate(Date d) | This method sets the Calendar selected day |
public Date getCurrentDate() | Returns the currently viewed date (as opposed to the selected date) |
public void setCurrentDate(Date d) | Sets the Calendar view on the given date, only the the month and year are being considered. |
public TimeZone getTimeZone() | Gets the Calendar timezone |
public void setTimeZone(TimeZone tmz) | Sets the Calendar timezone, if not specified Calendar will use the default timezone |
public Style getMonthViewSelectedStyle() | Gets the selected style of the month view component within the calendar |
public void setMonthViewSelectedStyle(Style s) | Sets the selected style of the month view component within the calendar |
public Style getMonthViewUnSelectedStyle() | Gets the un selected style of the month view component within the calendar |
public void setMonthViewUnSelectedStyle(Style s) | Sets the un selected style of the month view component within the calendar |
public void addActionListener(ActionListener l) | Fires when a change is made to the month view of this component |
public void removeActionListener(ActionListener l) | Fires when a change is made to the month view of this component |
public void addMonthChangedListener(ActionListener l) | Fires when a new month is selected |
public void removeMonthChangedListener(ActionListener l) | Fires when a new month is selected |
public void addDayActionListener(ActionListener l) | Adds an ActionListener to the day buttons. |
public void removeDayActionListener(ActionListener l) | Removes ActionListener from day buttons |
public void addDataChangedListener(DataChangedListener l) | Allows tracking selection changes in the calendar in real time |
public void removeDataChangedListener(DataChangedListener l) | Allows tracking selection changes in the calendar in real time |
public void addDataChangeListener(DataChangedListener l) | Deprecated Allows tracking selection changes in the calendar in real time |
public void removeDataChangeListener(DataChangedListener l) | Deprecated Allows tracking selection changes in the calendar in real time |
public boolean isChangesSelectedDateEnabled() | This flag determines if selected date can be changed by selecting an alternative date |
public void setChangesSelectedDateEnabled(boolean changesSelectedDateEnabled) | This flag determines if selected date can be changed by selecting an alternative date |
protected Button createDay() | Deprecated This method creates the Day Button Component for the Month View |
protected Label createDayTitle(int day) | This method creates the Day title Component for the Month View |
protected void updateButtonDayDate(Component dayButton, int year, int currentMonth, int day) | This method updates the Button day. |
protected void updateButtonDayDate(Component dayButton, int currentMonth, int day) | This method updates the Button day. |
protected void updateButtonDayDate(Button dayButton, int year, int currentMonth, int day) | Deprecated This method updates the Button day. |
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) | Deprecated This method updates the Button day. |
public boolean isTwoDigitMode() | When set to true days will be rendered as 2 digits with 0 preceding single digit days |
public void setTwoDigitMode(boolean twoDigitMode) | When set to true days will be rendered as 2 digits with 0 preceding single digit days |
public Collection<Date> getSelectedDays() | Gets the dates selected on the calendar or null if no date is selected |
public void setSelectedDays(Collection<Date> selectedDays) | Sets the dates to be selected on the calendar |
public void setSelectedDays(Collection<Date> selectedDays, String uiid) | Sets the dates to be selected on the calendar with a custom uiid. |
public String getSelectedDaysUIID() | |
public void setSelectedDaysUIID(String uiid) | Sets the selectedDays UIID to the given uiid. |
public void highlightDate(Date date, String uiid) | Highlights a date on the calendar using the supplied uiid. |
public void highlightDates(Collection<Date> dates, String uiid) | Highlights dates on the calendar using the supplied uiid. |
public void unHighlightDates(Collection<Date> dates) | Un-highlights dates on the calendar by removing the highlighting uiid. |
public void unHighlightDate(Date date) | Un-highlights dates on the calendar by removing the highlighting uiid. |
public boolean isMultipleSelectionEnabled() | If true multiple days can be selected on a calendar and “getSelectedDays()” will return the dates selected |
public void setMultipleSelectionEnabled(boolean multipleSelectionEnabled) | When set to true multiple days can be selected on a calendar and “getSelectedDays()” will return the dates selected |
protected Component 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. |
protected void bindDayListener(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 void setDayText(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 String getDayText(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. |
protected void setDayUIID(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. |
protected void setDayEnabled(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. |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From Container
encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, calcPreferredSize, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, deinitialize, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Constructor details
Calendar
public Calendar(long time)Parameters
timelong- time since epoch
Calendar
public Calendar()Calendar
public Calendar(long time, TimeZone tmz)Parameters
timelong- time since epoch
tmzTimeZone- a reference timezone
Calendar
public Calendar(Image leftArrowImage, Image rightArrowImage)Parameters
leftArrowImageImage- an image for calendar left arrow
rightArrowImageImage- an image for calendar right arrow
Calendar
public Calendar(long time, TimeZone tmz, Image leftArrowImage, Image rightArrowImage)Parameters
timelong- time since epoch
tmzTimeZone- a reference timezone
leftArrowImageImage- an image for calendar left arrow
rightArrowImageImage- an image for calendar right arrow
Method details
getSelectedDay
public long getSelectedDay()Returns
getDate
public Date getDate()Returns
setDate
public void setDate(Date d)Parameters
dDate- new date
setYearRange
public void setYearRange(int minYear, int maxYear)Parameters
minYearint- the min year
maxYearint- the max year
setSelectedDate
public void setSelectedDate(Date d)Parameters
dDate- the selected day
getCurrentDate
public Date getCurrentDate()Returns
setCurrentDate
public void setCurrentDate(Date d)Parameters
dDate- the date to set the calendar view on.
getTimeZone
public TimeZone getTimeZone()Returns
setTimeZone
public void setTimeZone(TimeZone tmz)Parameters
tmzTimeZone- the timezone
getMonthViewSelectedStyle
public Style getMonthViewSelectedStyle()Returns
setMonthViewSelectedStyle
public void setMonthViewSelectedStyle(Style s)Parameters
sStyle- style for the month view
getMonthViewUnSelectedStyle
public Style getMonthViewUnSelectedStyle()Returns
setMonthViewUnSelectedStyle
public void setMonthViewUnSelectedStyle(Style s)Parameters
sStyle- style for the month view
addActionListener
public void addActionListener(ActionListener l)Parameters
lActionListener- listener to add
removeActionListener
public void removeActionListener(ActionListener l)Parameters
lActionListener- listener to remove
addMonthChangedListener
public void addMonthChangedListener(ActionListener l)Parameters
lActionListener- listener to add
removeMonthChangedListener
public void removeMonthChangedListener(ActionListener l)Parameters
lActionListener- listener to remove
addDayActionListener
public void addDayActionListener(ActionListener l)Calendar.addActionListener and will only fire when an active day
is selected.Parameters
lActionListener- listener to add
removeDayActionListener
public void removeDayActionListener(ActionListener l)Parameters
lActionListener- listener to remove
addDataChangedListener
public void addDataChangedListener(DataChangedListener l)Parameters
lDataChangedListener- listener to add
removeDataChangedListener
public void removeDataChangedListener(DataChangedListener l)Parameters
lDataChangedListener- listener to remove
addDataChangeListener
public void addDataChangeListener(DataChangedListener l)Parameters
lDataChangedListener- listener to add
removeDataChangeListener
public void removeDataChangeListener(DataChangedListener l)Parameters
lDataChangedListener- listener to remove
isChangesSelectedDateEnabled
public boolean isChangesSelectedDateEnabled()Returns
setChangesSelectedDateEnabled
public void setChangesSelectedDateEnabled(boolean changesSelectedDateEnabled)Parameters
changesSelectedDateEnabledboolean- if true pressing on a date will cause the selected date to be changed to the pressed one
createDay
protected Button createDay()createDayComponent() insteadReturns
createDayTitle
protected Label createDayTitle(int day)Parameters
dayint- the relevant day values are 0-6 where 0 is Sunday.
Returns
updateButtonDayDate
protected void updateButtonDayDate(Component dayButton, int year, int currentMonth, int day)Parameters
dayButtonComponent- the button to be updated
yearint- the current year
currentMonthint- the current month
dayint- the new button day
updateButtonDayDate
protected void updateButtonDayDate(Component dayButton, int currentMonth, int day)Parameters
dayButtonComponent- the button to be updated
currentMonthint- the current month
dayint- the new button day
updateButtonDayDate
protected void updateButtonDayDate(Button dayButton, int year, int currentMonth, int day)Parameters
dayButtonButton- the button to be updated
yearint- the current year
currentMonthint- the current month
dayint- the new button day
updateButtonDayDate
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day)Parameters
dayButtonButton- the button to be updated
currentMonthint- the current month
dayint- the new button day
isTwoDigitMode
public boolean isTwoDigitMode()Returns
setTwoDigitMode
public void setTwoDigitMode(boolean twoDigitMode)Parameters
twoDigitModeboolean- the twoDigitMode to set
getSelectedDays
public Collection<Date> getSelectedDays()Returns
setSelectedDays
public void setSelectedDays(Collection<Date> selectedDays)Parameters
selectedDaysCollection<Date>- the multipleDateSelection to set
setSelectedDays
public void setSelectedDays(Collection<Date> selectedDays, String uiid)CalendarMultipleDay”, call this method without the
“uiid parameter”Parameters
selectedDaysCollection<Date>- the multipleDateSelection to set
uiidString- a custom uiid to be used in the dates selected
getSelectedDaysUIID
public String getSelectedDaysUIID()Returns
setSelectedDaysUIID
public void setSelectedDaysUIID(String uiid)Parameters
uiidString- the uiid to change to
highlightDate
public void highlightDate(Date date, String uiid)Parameters
dateDate- the date to be highlighted
uiidString- a custom uiid to be used in highlighting the date
highlightDates
public void highlightDates(Collection<Date> dates, String uiid)Parameters
datesCollection<Date>- the dates to be highlighted
uiidString- a custom uiid to be used in highlighting the dates
unHighlightDates
public void unHighlightDates(Collection<Date> dates)selectedDaysUIID uiid will be applied to any of the dates that
are part of selectedDays)Parameters
datesCollection<Date>- the dates to be un-highlighted
unHighlightDate
public void unHighlightDate(Date date)selectedDaysUIID uiid will be applied to the date if it is part
of selectedDays)Parameters
dateDate- the date to be un-highlighted
isMultipleSelectionEnabled
public boolean isMultipleSelectionEnabled()getSelectedDays()” will return the dates selectedReturns
setMultipleSelectionEnabled
public void setMultipleSelectionEnabled(boolean multipleSelectionEnabled)getSelectedDays()” will return the dates selectedParameters
multipleSelectionEnabledboolean- the multipleSelectionEnabled to set
createDayComponent
protected Component createDayComponent()Returns
bindDayListener
protected void bindDayListener(Component cmp, ActionListener l)Parameters
cmpComponent- day component returned by createDayComponent()
lActionListener- listener interface
setDayText
protected void setDayText(Component cmp, String text)Parameters
cmpComponent- day component returned by createDayComponent()
textString- the text set the component to
getDayText
protected String getDayText(Component cmp)Parameters
cmpComponent- day component returned by createDayComponent
Returns
setDayUIID
protected void setDayUIID(Component cmp, String uiid)Parameters
cmpComponent- day component returned by createDayComponent()
uiidString- the text set the component to
setDayEnabled
protected void setDayEnabled(Component cmp, boolean enable)Parameters
cmpComponent- day component returned by createDayComponent()
enableboolean- the text set the component to