TextField
A single line of editable plain text. The JTextField shows the text value declares, and every edit reports the field's whole text through onValueChange.
This field is strictly controlled: if onValueChange does not answer with a matching value, the field is settled back onto the declared value on the very next pass. It never ends up holding text the caller has not adopted. A callback that filters a keystroke rather than adopting it leaves the caret where that keystroke would have gone.
For incremental editing over a shared Document, undo/redo, or observing the text as a flow, drive the field with the DocumentState overload and a DocumentState from rememberDocumentState.
Parameters
the current text value
callback invoked with the field's new text when the field is edited; applying value is not itself reported
the SwingModifier applied to the underlying component
the preferred width in columns; 0 by default, taking the width from the text the field holds
whether the user can type into the field; true by default
See also
the DocumentState-driven overload for large or complex editors
A TextField driven by a raw DocumentListener instead of an onValueChange lambda. The documentListener is attached to the field's document as-is and removed on the same instance; pass a stable instance (e.g. remember {}) to avoid churn. It observes every change to that document, including the one that applies value.
This field is strictly controlled: if text the field settles on is not followed by value moving to match, it is settled back onto the declared value on the very next pass. It never ends up holding text the caller has not adopted.
For incremental editing over a shared Document, undo/redo, or observing the text as a flow, drive the field with the DocumentState overload and a DocumentState from rememberDocumentState.
Parameters
the current text value
the listener notified of document edits
the SwingModifier applied to the underlying component
the preferred width in columns; 0 by default, taking the width from the text the field holds
whether the user can type into the field; true by default
See also
the DocumentState-driven overload for large or complex editors
A TextField driven by a DocumentState. The field renders the state's own document, so text typed into the field and edits made through the state are the same content, and the caret is kept two-way with DocumentState.selection. The state is the single source of truth; there is no onValueChange.
Parameters
the hoistable text state the field renders and drives.
the SwingModifier applied to the underlying component
the preferred width in columns; 0 by default, taking the width from the text the field holds
whether the user can type into the field; true by default