This component models paragraphs that are composed of runs of character level attributes. Each paragraph may have a logical style attached to it which contains the default attributes to use if not overridden by attributes set on the paragraph or character run. Components and images may be embedded in the flow of text.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
javax.swing.text.StyledEditorKit
| Modifier and Type | Field and Description |
|---|---|
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JTextPane(StyledDocument
the document model doc)Creates a new |
| Modifier and Type | Method and Description |
|---|---|
| public Style | Returns: the newStylethe name of the style (must be unique within the
collection of named styles). The name may be nm, Style null
if the style is unnamed, but the caller is responsible
for managing the reference returned as an unnamed style can't
be fetched by name. An unnamed style may be useful for things
like character attribute overrides such as found in a style
run.the parent style. This may be parent)null
if unspecified
attributes need not be resolved in some other style.Adds a new style into the logical style hierarchy. |
| protected EditorKit | Returns: the editor kitOverrides javax. Creates the |
| public AttributeSet | Returns: the attributes, ornullFetches the character attributes in effect at the
current location of the caret, or |
| public MutableAttributeSet | |
| public Style | Returns: theStyleFetches the logical style assigned to the paragraph represented
by the current position of the caret, or |
| public AttributeSet | Returns: the attributesFetches the current paragraph attributes in effect
at the location of the caret, or |
| public Style | |
| public StyledDocument | |
| protected final StyledEditorKit | |
| public String | Returns: the string "TextPaneUI"Overrides javax. Returns the class ID for the UI. |
| public void | insertComponent(Component
the component to insert c)Inserts a component into the document as a replacement for the currently selected content. |
| public void | insertIcon(Icon
the icon to insert g)Inserts an icon into the document as a replacement for the currently selected content. |
| protected String | Returns: a string representation of thisJTextPaneOverrides javax. Returns a string representation of this |
| public void | removeStyle(String
the name of the style to remove nm)Removes a named non- |
| public void | replaceSelection(String
the content to replace the selection with content)Overrides javax. Replaces the currently selected content with new content represented by the given string. |
| private void | |
| public void | setCharacterAttributes(AttributeSet
the attributes attr, boolean if true, then replace the existing attributes first replace)Applies the given attributes to character content. |
| public void | setDocument(Document
the document to display/edit doc)Overrides javax. Associates the editor with a text document. |
| public final void | setEditorKit(EditorKit
the desired editor behavior kit)Overrides javax. Sets the currently installed kit for handling content. |
| public void | setLogicalStyle(Style
the logical style to assign to the paragraph,
or s)null for no styleSets the logical style to use for the paragraph at the current caret position. |
| public void | setParagraphAttributes(AttributeSet
the non- attr, boolean null attributesif true, replace the existing attributes first replace)Applies the given attributes to paragraphs. |
| public void | setStyledDocument(StyledDocument
the document to display/edit doc)Associates the editor with a text document. |
| private void | writeObject(ObjectOutputStream
the output stream s)Hides javax. See |
| uiClassID | back to summary |
|---|---|
| private static final String uiClassID Hides javax.
| |
| JTextPane | back to summary |
|---|---|
| public JTextPane() Creates a new | |
| JTextPane | back to summary |
|---|---|
| public JTextPane(StyledDocument doc) Creates a new
| |
| addStyle | back to summary |
|---|---|
| public Style addStyle(String nm, Style parent) Adds a new style into the logical style hierarchy. Style attributes resolve from bottom up so an attribute specified in a child will override an attribute specified in the parent.
| |
| createDefaultEditorKit | back to summary |
|---|---|
| protected EditorKit createDefaultEditorKit() Overrides javax. Creates the
| |
| getCharacterAttributes | back to summary |
|---|---|
| public AttributeSet getCharacterAttributes() Fetches the character attributes in effect at the
current location of the caret, or
| |
| getInputAttributes | back to summary |
|---|---|
| public MutableAttributeSet getInputAttributes() Gets the input attributes for the pane.
| |
| getLogicalStyle | back to summary |
|---|---|
| public Style getLogicalStyle() Fetches the logical style assigned to the paragraph represented
by the current position of the caret, or
| |
| getParagraphAttributes | back to summary |
|---|---|
| public AttributeSet getParagraphAttributes() Fetches the current paragraph attributes in effect
at the location of the caret, or
| |
| getStyle | back to summary |
|---|---|
| public Style getStyle(String nm) Fetches a named non- | |
| getStyledDocument | back to summary |
|---|---|
| public StyledDocument getStyledDocument() Fetches the model associated with the editor.
| |
| getStyledEditorKit | back to summary |
|---|---|
| protected final StyledEditorKit getStyledEditorKit() Gets the editor kit.
| |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns the class ID for the UI.
| |
| insertComponent | back to summary |
|---|---|
| public void insertComponent(Component c) Inserts a component into the document as a replacement for the currently selected content. If there is no selection the component is effectively inserted at the current position of the caret. This is represented in the associated document as an attribute of one character of content. The component given is the actual component used by the JTextPane. Since components cannot be a child of more than one container, this method should not be used in situations where the model is shared by text components.
The component is placed relative to the text baseline
according to the value returned by
| |
| insertIcon | back to summary |
|---|---|
| public void insertIcon(Icon g) Inserts an icon into the document as a replacement for the currently selected content. If there is no selection the icon is effectively inserted at the current position of the caret. This is represented in the associated document as an attribute of one character of content. | |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides javax. Returns a string representation of this
| |
| removeStyle | back to summary |
|---|---|
| public void removeStyle(String nm) Removes a named non-
| |
| replaceSelection | back to summary |
|---|---|
| public void replaceSelection(String content) Overrides javax. Replaces the currently selected content with new content represented by the given string. If there is no selection this amounts to an insert of the given text. If there is no replacement text this amounts to a removal of the current selection. The replacement text will have the attributes currently defined for input at the point of insertion. If the document is not editable, beep and return. | |
| replaceSelection | back to summary |
|---|---|
| private void replaceSelection(String content, boolean checkEditable) | |
| setCharacterAttributes | back to summary |
|---|---|
| public void setCharacterAttributes(AttributeSet attr, boolean replace) Applies the given attributes to character content. If there is a selection, the attributes are applied to the selection range. If there is no selection, the attributes are applied to the input attribute set which defines the attributes for any new text that gets inserted.
| |
| setDocument | back to summary |
|---|---|
| public void setDocument(Document doc) Overrides javax. Associates the editor with a text document. This
must be a
| |
| setEditorKit | back to summary |
|---|---|
| public final void setEditorKit(EditorKit kit) Overrides javax. Sets the currently installed kit for handling content. This is the bound property that establishes the content type of the editor.
| |
| setLogicalStyle | back to summary |
|---|---|
| public void setLogicalStyle(Style s) Sets the logical style to use for the paragraph at the current caret position. If attributes aren't explicitly set for character and paragraph attributes they will resolve through the logical style assigned to the paragraph, which in term may resolve through some hierarchy completely independent of the element hierarchy in the document.
| |
| setParagraphAttributes | back to summary |
|---|---|
| public void setParagraphAttributes(AttributeSet attr, boolean replace) Applies the given attributes to paragraphs. If there is a selection, the attributes are applied to the paragraphs that intersect the selection. If there is no selection, the attributes are applied to the paragraph at the current caret position.
| |
| setStyledDocument | back to summary |
|---|---|
| public void setStyledDocument(StyledDocument doc) Associates the editor with a text document. The currently registered factory is used to build a view for the document, which gets displayed by the editor.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Hides javax. See
| |