Java Reference
In-Depth Information
Without knowing which type of model you were working with, what you might do at this
level is change some display characteristic of the JFormattedTextField . More typically, though,
you'll change a custom aspect for the model's editor.
JSpinner.DateEditor Class
The DateEditor allows you to customize the date display (and entry) using various aspects of
the SimpleDateFormat class of the java.text package. See the Javadoc for SimpleDateFormat for
a complete listing of the available formatting patterns. If you don't like the default display
output, you can modify it by passing in a new format to the second constructor.
public JSpinner.DateEditor(JSpinner spinner)
SpinnerModel model = new SpinnerDateModel();
JSpinner spinner = new JSpinner(model);
JComponent editor = JSpinner.DateEditor(spinner);
spinner.setEditor(editor);
public JSpinner.DateEditor(JSpinner spinner, String dateFormatPattern)
SpinnerModel model = new SpinnerDateModel();
JSpinner spinner = new JSpinner(model);
JComponent editor = JSpinner.DateEditor(spinner, "MMMM yyyy");
spinner.setEditor(editor);
By default, the format is M/d/yy h:mm a , or 12/25/04 12:34 PM for some time on Christmas
in 2004 (or 1904, 1804, and so on). The latter example will show December 2004.
The editor has the two properties shown in Table 14-7.
Table 14-7. JSpinner.DateEditor Properties
Property Name
Data Type
Access
format
SimpleDateFormat
Read-only
model
SpinnerDateModel
Read-only
JSpinner.ListEditor Class
When working with the SpinnerListModel , the ListEditor provides no special formatting
support. Instead, it offers type-ahead support. Since all entries of the model are known, the
editor tries to match the characters the user has already entered with the start of one of those
entries. There is only one constructor, but you should never need to access it.
public JSpinner.ListEditor(JSpinner spinner)
As shown in Table 14-8, ListEditor has only a single property.
Search WWH ::




Custom Search