Java Reference
In-Depth Information
public JFormattedTextField(JFormattedTextField.AbstractFormatterFactory factory,
Object currentValue)
DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd");
DateFormatter displayFormatter = new DateFormatter(displayFormat);
DateFormat editFormat = new SimpleDateFormat("MM/dd/yy");
DateFormatter editFormatter = new DateFormatter(editFormat);
DefaultFormatterFactory factory = new DefaultFormatterFactory(
displayFormatter, displayFormatter, editFormatter);
JFormattedTextField formattedField = new JFormattedTextField(factory, new Date());
public JFormattedTextField(Object value)
JFormattedTextField formattedField = new JFormattedTextField(new Date());
The no-argument version requires you to configure it later. The other constructors allow
you to configure what and how input will be accepted into the component.
JFormattedTextField Properties
Table 15-8 shows the eight properties of JFormattedTextField . Instead of getting the contents
of the JFormattedTextField as a String via the text property, as you would with a JTextField ,
you get it as an Object via the value property. Thus, if your formatter were for a Date object, the
value you get back could be cast to type java.util.Date .
Table 15-8. JFormattedTextField Properties
Property Name
Data Type
Access
actions
Action[ ]
Read-only
document
Document
Write-only
editValid
boolean
Read-only
focusLostBehavior
int
Read-write
formatter
JFormattedTextField.AbstractFormatter
Read-only
formatterFactory
JFormattedTextField.AbstractFormatterFactory
Read-write bound
UIClassID
String
Read-only
value
Object
Read-write bound
Listing 15-14 demonstrates the user of JFormattedTextField with custom formatters and
factories. Notice that when you edit the bottom text field, the display format and edit format
are different.
Search WWH ::




Custom Search