Class DateSpinner

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class DateSpinner extends JSpinner
DateSpinner is a spinner that is specialized in displaying or editing a a date or time.

To change the value, you can use JSpinner.setValue(Object) and pass in a Date. To get the Date, using JSpinner.getValue().

See Also:
  • Field Details

  • Constructor Details

    • DateSpinner

      public DateSpinner()
      Creates a date spinner using locale default as the format string.
    • DateSpinner

      public DateSpinner(String format)
      Creates a date spinner using the specified format string.
      Parameters:
      format - the format string as defined in SimpleDateFormat.
    • DateSpinner

      public DateSpinner(String format, Date date)
      Creates a date spinner using the specified format string and an initial value.
      Parameters:
      format - the format string as defined in SimpleDateFormat.
      date - initial value
  • Method Details

    • setFormat

      public void setFormat(String format)
      Sets the date format string used by this DateSpinner. Please note, this method call will recreate the DateEditor used by DateSpinner.
      Parameters:
      format - the format
    • customizeSpinner

      protected void customizeSpinner()
      Customizes the spinner.
    • createDateEditor

      protected JSpinner.DateEditor createDateEditor(String format)
      Creates the DateEditor.
      Parameters:
      format - the format
      Returns:
      the DateEditor.
    • setCommitsOnValidEdit

      public void setCommitsOnValidEdit(boolean commit)
      Sets when edits are published back to the JFormattedTextField. If true, commitEdit is invoked after every valid edit (any time the text is edited). On the other hand, if this is false than the DefaultFormatter does not publish edits back to the JFormattedTextField. As such, the only time the value of the JFormattedTextField will change is when commitEdit is invoked on JFormattedTextField, typically when enter is pressed or focus leaves the JFormattedTextField.
      Parameters:
      commit - Used to indicate when edits are committed back to the JTextComponent
    • getCommitsOnValidEdit

      public boolean getCommitsOnValidEdit()
      Returns when edits are published back to the JFormattedTextField.
      Returns:
      true if edits are committed aftereveryy valid edit
    • setOverwriteMode

      public void setOverwriteMode(boolean overwriteMode)
      Configures the behavior when inserting characters. If overwriteMode is true (the default), new characters overwrite existing characters in the model.
      Parameters:
      overwriteMode - Indicates if overwrite or overstrike mode is used
    • getOverwriteMode

      public boolean getOverwriteMode()
      Returns the behavior when inserting characters.
      Returns:
      true if newly inserted characters overwrite existing characters
    • setAllowsInvalid

      public void setAllowsInvalid(boolean allowsInvalid)
      Sets whether or not the value being edited is allowed to be invalid for a length of time (that is, stringToValue throws a ParseException). It is often convenient to allow the user to temporarily input an invalid value.
      Parameters:
      allowsInvalid - Used to indicate if the edited value must always be valid
    • getAllowsInvalid

      public boolean getAllowsInvalid()
      Returns whether or not the value being edited is allowed to be invalid for a length of time.
      Returns:
      false if the edited value must always be valid
    • setTimeZone

      public void setTimeZone(TimeZone zone)
      Sets the time zone for the calendar of this DateFormat object.
      Parameters:
      zone - the given new time zone.
    • getTimeZone

      public TimeZone getTimeZone()
      Gets the time zone.
      Returns:
      the time zone associated with the calendar of DateFormat.
    • setLenient

      public void setLenient(boolean lenient)
      Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.
      Parameters:
      lenient - when true, parsing is lenient
      See Also:
    • isLenient

      public boolean isLenient()
      Tell whether date/time parsing is to be lenient. It is the same as DateFormat.isLenient().
      Returns:
      true or false.