TextPane

@Composable
fun TextPane(value: @Nls String, onValueChange: (@Nls String) -> Unit, modifier: SwingModifier = SwingModifier, editable: Boolean = true)

Editable text carrying graphical attributes - fonts, colors, embedded icons and components - over the styled document a JTextPane holds.

The binding is reactive in both directions - value is pushed onto the pane, and edits the user makes are reported through onValueChange.

This pane is strictly controlled: text the pane 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 pane 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 pane with the DocumentState overload (TextPane) and a DocumentState from rememberDocumentState.

Parameters

value

the current text

onValueChange

callback invoked with the pane's new text when the pane is edited; applying value is not itself reported

modifier

the SwingModifier applied to the underlying component

editable

whether the user can type into the pane; true by default

See also

the DocumentState-driven overload for large or complex editors


@Composable
fun TextPane(value: @Nls String, documentListener: DocumentListener, modifier: SwingModifier = SwingModifier, editable: Boolean = true)

A TextPane driven by a raw DocumentListener instead of an onValueChange lambda. The listener observes the document the pane currently holds and follows it across a document swap; 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 pane is strictly controlled: text the pane 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 pane 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 pane with the DocumentState overload (TextPane) and a DocumentState from rememberDocumentState.

Parameters

value

the current text

documentListener

the listener notified of document edits

modifier

the SwingModifier applied to the underlying component

editable

whether the user can type into the pane; true by default

See also

the DocumentState-driven overload for large or complex editors


@Composable
fun TextPane(state: DocumentState, modifier: SwingModifier = SwingModifier, editable: Boolean = true)

A TextPane driven by a DocumentState. The pane renders the state's own document, so text typed into the pane 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.

A JTextPane renders a styled document, so state must wrap a StyledDocument - the model rememberDocumentState(contentType = "text/rtf") builds.

Parameters

state

the hoistable text state, over a StyledDocument, the pane renders and drives.

modifier

the SwingModifier applied to the underlying component

editable

whether the user can type into the pane; true by default

See also