rememberDocumentState
Creates and remembers a DocumentState over a fresh document in the language contentType names, seeded with initialText.
The content type picks the editor kit registered for it, which both builds the document and reads initialText as source written in that language: text/plain yields a PlainDocument holding the text as characters, text/html an HTMLDocument holding the markup parsed, text/rtf a StyledDocument - the model a JTextPane requires. An EditorPane bound to the state renders it through that same kit.
A kit reads its own language and nothing else, so source it cannot make sense of contributes nothing: a text/rtf state seeded with text that is not RTF starts empty rather than reporting it, an empty result being what source that legitimately renders to nothing produces too.
A later change to initialText neither recreates nor mutates the state; drive the field afterwards through the returned state's DocumentState.text, DocumentState.edit and related members. A later change to contentType builds a new state in the new language, seeded from initialText as it reads on that pass.
Parameters
the source, written in contentType's language, the document starts with.
the MIME type naming the kit that builds and reads the document.
See also
Throws
if no editor kit is registered for contentType.
Creates and remembers a DocumentState over a fresh document built by kit and seeded by reading initialText through it. Reach for this over the contentType form when the kit is configured - a style sheet of your own, a custom parser, a kit class the registry does not name.
The state is tied to the kit's identity: a different kit builds a new state. Pass a kit that outlives a recomposition - one kept in a remember - so the state is rebuilt only when the kit really changes.
Parameters
the editor kit that builds the document, reads initialText into it, and renders it.
the source, written in the kit's language, the document starts with.
See also
Creates and remembers a DocumentState over an existing document, leaving its current content in place. The bound field renders this exact document, so a caller keeping a reference to it observes the same edits the state does.
Name the kit that reads the document's language to have an EditorPane render it through that kit; without one the pane renders the document through its own, which is plain text.
The state is tied to the identity of both: a different document or kit builds a new state, the field switches to rendering it, and the previous state releases what it held. Pass values that outlive a recomposition - owned outside the composition or kept in a remember - so the state is rebuilt only when what it renders really changes.
Parameters
the document the state adopts and the field renders.
the editor kit that reads the document's language, or null to leave the choice to the field.