Class DatePickerFormatter

java.lang.Object
javax.swing.JFormattedTextField.AbstractFormatter
org.jdesktop.swingx.calendar.DatePickerFormatter
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DatePickerFormatter.DatePickerFormatterUIResource

public class DatePickerFormatter extends JFormattedTextField.AbstractFormatter
Default formatter for the JXDatePicker component. It can handle a variety of date formats.
See Also:
  • Field Details

    • LOG

      private static final Logger LOG
    • _formats

      private DateFormat[] _formats
  • Constructor Details

    • DatePickerFormatter

      public DatePickerFormatter()
      Instantiates a formatter with the localized format patterns defined in the swingx.properties. These formats are localizable and fields may be re-arranged, such as swapping the month and day fields. The keys for localizing these fields are:
      • JXDatePicker.longFormat
      • JXDatePicker.mediumFormat
      • JXDatePicker.shortFormat
    • DatePickerFormatter

      public DatePickerFormatter(DateFormat[] formats)
      Instantiates a formatter with the given date formats. If the array is null, default formats are created from the localized patterns in swingx.properties. If empty?
      Parameters:
      formats - the array of formats to use. May be null to use defaults or empty to do nothing (?), but must not contain null formats.
    • DatePickerFormatter

      public DatePickerFormatter(Locale locale)
      Instantiates a formatter with default date formats in the given locale. The default formats are created from the localized patterns in swingx.properties.
      Parameters:
      locale - the Locale the use for the default formats.
    • DatePickerFormatter

      public DatePickerFormatter(DateFormat[] formats, Locale locale)
      Instantiates a formatter with the given formats and locale. PENDING JW: makes no sense as a public constructor because the locale is ignored if the formats are null. So has same public behaviour as the constructor with formats only ...
      Parameters:
      formats -
      locale -
  • Method Details

    • getFormats

      public DateFormat[] getFormats()
      Returns an array of the formats used by this formatter.
      Returns:
      the formats used by this formatter, guaranteed to be not null.
    • stringToValue

      public Object stringToValue(String text) throws ParseException
      Specified by:
      stringToValue in class JFormattedTextField.AbstractFormatter
      Throws:
      ParseException
    • valueToString

      public String valueToString(Object value) throws ParseException
      Specified by:
      valueToString in class JFormattedTextField.AbstractFormatter
      Throws:
      ParseException
    • createDefaultFormats

      protected DateFormat[] createDefaultFormats(Locale locale)
      Creates and returns the localized default formats. First tries to add formats created using the patterns stored in the UIManager. If there are no patterns, use the DateFormat's instance with style DateFormat.SHORT.
      Returns:
      the localized default formats.
    • addSystemDefaultFormat

      private void addSystemDefaultFormat(List<DateFormat> f, Locale locale)
      Adds the system's default DateFormat. This implementation adds a dateInstance of style DateFormat.SHORT.
      Parameters:
      f - the List of formats to add to
      locale - the Locale to use for the formatter.
    • addFormat

      private void addFormat(List<DateFormat> f, String key, Locale locale)
      Creates and adds a DateFormat to the given list. Looks up a format pattern registered in the UIManager for the given key and tries to create a SimpleDateFormat. Does nothing if there is no format pattern registered or the pattern is invalid.
      Parameters:
      f - the list of formats
      key - the key for getting the pattern from the UI