Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class MaterialDatePicker

  1. Object
  2. Component
  3. Container
  4. MaterialDatePicker

ImplementsAnimation, Editable, InternalPickerWidget, Iterable<Component>, StyleListener

A date picker in the Material 3 style: the chosen date in large type over a month of days, a grid of years behind the month’s name, and a text field for somebody who would sooner type.

A Picker opens one in a dialog when the theme constant pickerStyle is material. It is a component like any other and can be placed in a form directly:

MaterialDatePicker picker = new MaterialDatePicker();
picker.setDate(new Date());
picker.addActionListener(e -> Log.p("Chosen: " + picker.getDate()));

Form form = new Form("Date", new BorderLayout());
form.add(BorderLayout.CENTER, picker);
form.show();

The month of a Material date picker The years The date typed

Under a mouse the day the pointer is over is marked, and a month asked for with the arrows slides in over the one shown.

The value is a Date. Its time of day is kept as it was given, so a date chosen here does not move an appointment to midnight.

Styling

PickerMaterialOverline is the small title and PickerMaterialHeadline the chosen date; PickerMaterialButton the name of the month, the arrows and the pencil. PickerMaterialWeekday gives the initials of the days their colour and PickerMaterialDay the days theirs: its selected style is the circle of the chosen day, background and foreground, and its disabled style a day outside the range. PickerMaterialYear is a year in the grid, PickerMaterialField the text field and PickerMaterialError what is said about a date that cannot be read.

A date picker restyled from CSS

Constructors

public MaterialDatePicker()A picker showing today.

Methods

public Date getDate()The chosen date, at the time of day of the date last set.
public void setDate(Date date)Chooses a date and shows its month.
public Object getValue()The currently selected value.
public void setValue(Object value)Moves the selection to value.
public void setDateRange(Date first, Date last)The first and the last day that can be chosen.
public void setYearRange(int first, int last)The years the grid of years offers, 1900 to 2100 unless set.
public void setFirstDayOfWeek(int calendarDay)The day a week starts on, as java.util.Calendar numbers them: Calendar.SUNDAY by default, Calendar.MONDAY for most of Europe.
public int getFirstDayOfWeek()
public void setTitle(String title)The small title over the date: “Select date” unless set.
public String getTitle()
public void addActionListener(ActionListener l)Told when the user chooses another date.
public void removeActionListener(ActionListener l)
public void setAnimationTime(long millis)Stops the clock the months slide by at a time, for a screenshot of a month coming in or a test of it.
public boolean isInputMode()Whether the date is typed and not picked from the month.
public void setInputMode(boolean v)

Inherited fields

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, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, 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

MaterialDatePicker

public MaterialDatePicker()
A picker showing today.

Method details

getDate

public Date getDate()
The chosen date, at the time of day of the date last set.

setDate

public void setDate(Date date)
Chooses a date and shows its month. A date outside the range is brought to the nearest end of it. A null date is ignored.

getValue

public Object getValue()
The currently selected value.

Returns

the selection, in whatever type this implementation documents; never null once the widget has been laid out

setValue

public void setValue(Object value)

Moves the selection to value.

The widget scrolls to the new selection rather than jumping, when it is already on screen.

Parameters

value Object
the new selection, in the type this implementation documents. A value outside the widget’s range is clamped into it.

setDateRange

public void setDateRange(Date first, Date last)
The first and the last day that can be chosen. Either may be null for no limit on that side.

setYearRange

public void setYearRange(int first, int last)
The years the grid of years offers, 1900 to 2100 unless set. A date range narrows them further.

setFirstDayOfWeek

public void setFirstDayOfWeek(int calendarDay)
The day a week starts on, as java.util.Calendar numbers them: Calendar.SUNDAY by default, Calendar.MONDAY for most of Europe.

getFirstDayOfWeek

public int getFirstDayOfWeek()

setTitle

public void setTitle(String title)
The small title over the date: “Select date” unless set.

getTitle

public String getTitle()

addActionListener

public void addActionListener(ActionListener l)
Told when the user chooses another date.

removeActionListener

public void removeActionListener(ActionListener l)

setAnimationTime

public void setAnimationTime(long millis)
Stops the clock the months slide by at a time, for a screenshot of a month coming in or a test of it. A negative value returns to the clock.

isInputMode

public boolean isInputMode()
Whether the date is typed and not picked from the month.

setInputMode

public void setInputMode(boolean v)