Class SpinnerDateModel

All Implemented Interfaces:
Serializable, SpinnerModel

public class SpinnerDateModel extends AbstractSpinnerModel implements Serializable
A SpinnerModel for sequences of Dates. The upper and lower bounds of the sequence are defined by properties called start and end and the size of the increase or decrease computed by the nextValue and previousValue methods is defined by a property called calendarField. The start and end properties can be null to indicate that the sequence has no lower or upper limit.

The value of the calendarField property must be one of the java.util.Calendar constants that specify a field within a Calendar. The getNextValue and getPreviousValue methods change the date forward or backwards by this amount. For example, if calendarField is Calendar.DAY_OF_WEEK, then nextValue produces a Date that's 24 hours after the current value, and previousValue produces a Date that's 24 hours earlier.

The legal values for calendarField are:

  • Calendar.ERA
  • Calendar.YEAR
  • Calendar.MONTH
  • Calendar.WEEK_OF_YEAR
  • Calendar.WEEK_OF_MONTH
  • Calendar.DAY_OF_MONTH
  • Calendar.DAY_OF_YEAR
  • Calendar.DAY_OF_WEEK
  • Calendar.DAY_OF_WEEK_IN_MONTH
  • Calendar.AM_PM
  • Calendar.HOUR
  • Calendar.HOUR_OF_DAY
  • Calendar.MINUTE
  • Calendar.SECOND
  • Calendar.MILLISECOND
However some UIs may set the calendarField before committing the edit to spin the field under the cursor. If you only want one field to spin you can subclass and ignore the setCalendarField calls.

This model inherits a ChangeListener. The ChangeListeners are notified whenever the models value, calendarField, start, or end properties changes.

Since:
1.4
See Also:
  • Field Summary

    Fields declared in class javax.swing.AbstractSpinnerModel

    listenerList
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a SpinnerDateModel whose initial value is the current date, calendarField is equal to Calendar.DAY_OF_MONTH, and for which there are no start/end limits.
    SpinnerDateModel(Date value, Comparable<Date> start, Comparable<Date> end, int calendarField)
    Creates a SpinnerDateModel that represents a sequence of dates between start and end.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the Calendar field that is added to or subtracted from by the nextValue and previousValue methods.
    Returns the current element in this sequence of Dates.
    Returns the last Date in the sequence.