Class MaterialDatePicker

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.ui.spinner.MaterialDatePicker
All Implemented Interfaces:
Animation, Editable, StyleListener, InternalPickerWidget, Iterable<Component>

public class MaterialDatePicker extends Container implements InternalPickerWidget

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

  • 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()
      Description copied from interface: InternalPickerWidget

      The currently selected value.

      Returns

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

      Specified by:
      getValue in interface InternalPickerWidget
    • setValue

      public void setValue(Object value)
      Description copied from interface: InternalPickerWidget

      Moves the selection to value.

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

      Parameters
      • value: the new selection, in the type this implementation documents. A value outside the widget's range is clamped into it.
      Specified by:
      setValue in interface InternalPickerWidget
    • 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)