| Connects a String typed ValueModel and a JTextField or JTextArea.
At construction time the text component content is updated
with the subject's contents.
This connector has been designed for text components that display a plain
String. In case of a JEditorPane, the binding may require more information
then the plain String, for example styles. Since this is outside the scope
of this connector, the public constructors prevent a construction for
general JTextComponents. If you want to establish a one-way binding for
a display JEditorPane, use a custom listener instead.
This class provides limited support for handling
subject value modifications while updating the subject.
If a Document change initiates a subject value update, the subject
will be observed and a property change fired by the subject will be
handled - if any. In most cases, the subject will notify about a
change to the text that was just set by this connector.
However, in some cases the subject may decide to modify this text,
for example to ensure upper case characters.
Since at this moment, this adapter's Document is still write-locked,
the Document update is performed later using
SwingUtilities#invokeLater .
Note:
Such an update will typically change the Caret position in JTextField's
and other JTextComponent's that are synchronized using this class.
Hence, the subject value modifications can be used with
commit-on-focus-lost text components, but typically not with a
commit-on-key-typed component. For the latter case, you may consider
using a custom DocumentFilter .
Constraints:
The ValueModel must be of type String .
Examples:
ValueModel lastNameModel = new PropertyAdapter(customer, "lastName", true);
JTextField lastNameField = new JTextField();
TextComponentConnector.connect(lastNameModel, lastNameField);
ValueModel codeModel = new PropertyAdapter(shipment, "code", true);
JTextField codeField = new JTextField();
TextComponentConnector connector =
new TextComponentConnector(codeModel, codeField);
connector.updateTextComponent();
author: Karsten Lentzsch version: $Revision: 1.9 $ See Also: ValueModel See Also: Document See Also: PlainDocument since: 1.2 |