TextArea
Multiple lines of editable plain text. The JTextArea shows the text value declares, and every edit reports the area's whole text through onValueChange.
This area is strictly controlled: text the area settles on that onValueChange does not answer with a matching value is settled back onto the declared value on the very next pass, so the area 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 area with the DocumentState overload (TextArea) and a DocumentState from rememberDocumentState.
Parameters
the current text value
callback invoked with the area's new text when the area is edited; applying value is not itself reported
the SwingModifier applied to the underlying component
the preferred height in rows; the area is at least this tall, and 0, the default, takes the height from the text it holds
the preferred width in columns; the area is at least this wide, and 0, the default, takes the width from the text it holds
whether the user can type into the area; true by default
whether lines too long for the area's width are wrapped onto the next line; false by default, so long lines run past the width
whether wrapped lines break at word boundaries rather than at character boundaries; false by default, and only consulted while lineWrap is on
the number of characters a tab expands to, 8 by default
See also
the DocumentState-driven overload for large or complex editors
A TextArea driven by a raw DocumentListener instead of an onValueChange lambda. The documentListener is attached to the area's document as-is and removed on the same instance; pass a stable instance (e.g. remember {}) to avoid churn. Being attached as-is, it observes every change to that document, including the one that applies value.
This area is strictly controlled: text the area settles on that is not followed by value moving to match is settled back onto the declared value on the very next pass, so the area 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 area with the DocumentState overload (TextArea) 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 height in rows; the area is at least this tall, and 0, the default, takes the height from the text it holds
the preferred width in columns; the area is at least this wide, and 0, the default, takes the width from the text it holds
whether the user can type into the area; true by default
whether lines too long for the area's width are wrapped onto the next line; false by default, so long lines run past the width
whether wrapped lines break at word boundaries rather than at character boundaries; false by default, and only consulted while lineWrap is on
the number of characters a tab expands to, 8 by default
See also
the DocumentState-driven overload for large or complex editors
A TextArea driven by a DocumentState. The area renders the state's own document, so text typed into the area 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 area renders and drives.
the SwingModifier applied to the underlying component
the preferred height in rows; the area is at least this tall, and 0, the default, takes the height from the text it holds
the preferred width in columns; the area is at least this wide, and 0, the default, takes the width from the text it holds
whether the user can type into the area; true by default
whether lines too long for the area's width are wrapped onto the next line; false by default, so long lines run past the width
whether wrapped lines break at word boundaries rather than at character boundaries; false by default, and only consulted while lineWrap is on
the number of characters a tab expands to, 8 by default