javax.swing.text

Class StyledEditorKit

public class StyledEditorKit extends DefaultEditorKit

An {@link EditorKit} that supports editing styled text.
Nested Class Summary
static classStyledEditorKit.AlignmentAction
Sets the alignment attribute on the selected text.
static classStyledEditorKit.BoldAction
Toggles the bold attribute for the selected text.
static classStyledEditorKit.FontFamilyAction
Sets the font family attribute on the selected text.
static classStyledEditorKit.FontSizeAction
Sets the font size attribute on the selected text.
static classStyledEditorKit.ForegroundAction
Sets the foreground color attribute on the selected text.
static classStyledEditorKit.ItalicAction
Toggles the italic attribute for the selected text.
abstract static classStyledEditorKit.StyledTextAction
The abstract superclass of all styled TextActions.
static classStyledEditorKit.UnderlineAction
Toggles the underline attribute for the selected text.
Constructor Summary
StyledEditorKit()
Creates a new instance of StyledEditorKit.
Method Summary
Objectclone()
Creates an exact copy of this StyledEditorKit.
DocumentcreateDefaultDocument()
Creates the default {@link Document} supported by this EditorKit.
protected voidcreateInputAttributes(Element element, MutableAttributeSet set)
Copies the text attributes from element to set.
voiddeinstall(JEditorPane component)
Deinstalls this EditorKit from the specified {@link JEditorPane}.
Action[]getActions()
Returns the Actions supported by this {@link EditorKit}.
ElementgetCharacterAttributeRun()
Returns the {@link Element} that represents the character run at the current caret position.
MutableAttributeSetgetInputAttributes()
Returns the current input attributes.
ViewFactorygetViewFactory()
Returns a {@link ViewFactory} that is able to create {@link View}s for {@link Element}s that are supported by this EditorKit, namely the following types of Elements:
  • {@link AbstractDocument#ContentElementName}
  • {@link AbstractDocument#ParagraphElementName}
  • {@link AbstractDocument#SectionElementName}
  • {@link StyleConstants#ComponentElementName}
  • {@link StyleConstants#IconElementName}
voidinstall(JEditorPane component)
Installs this EditorKit on the specified {@link JEditorPane}.

Constructor Detail

StyledEditorKit

public StyledEditorKit()
Creates a new instance of StyledEditorKit.

Method Detail

clone

public Object clone()
Creates an exact copy of this StyledEditorKit.

Returns: an exact copy of this StyledEditorKit

createDefaultDocument

public Document createDefaultDocument()
Creates the default {@link Document} supported by this EditorKit. This is an instance of {@link DefaultStyledDocument} in this case but may be overridden by subclasses.

Returns: an instance of DefaultStyledDocument

createInputAttributes

protected void createInputAttributes(Element element, MutableAttributeSet set)
Copies the text attributes from element to set. This is called everytime when the caret position changes to keep track of the current input attributes. The attributes in set are cleaned before adding the attributes of element. This method filters out attributes for element names, Icons and Components.

Parameters: element the Element from which to copy the text attributes set the inputAttributes to copy the attributes to

deinstall

public void deinstall(JEditorPane component)
Deinstalls this EditorKit from the specified {@link JEditorPane}. This basically involves removing all listeners from JEditorPane that have been set up by this EditorKit.

Parameters: component the JEditorPane from which to deinstall this EditorKit

getActions

public Action[] getActions()
Returns the Actions supported by this {@link EditorKit}. This includes the {@link BoldAction}, {@link ItalicAction} and {@link UnderlineAction} as well as the Actions supported by {@link DefaultEditorKit}. The other Actions of StyledEditorKit are not returned here, since they require a parameter and thus custom instantiation.

Returns: the Actions supported by this {@link EditorKit}

getCharacterAttributeRun

public Element getCharacterAttributeRun()
Returns the {@link Element} that represents the character run at the current caret position.

Returns: the {@link Element} that represents the character run at the current caret position

getInputAttributes

public MutableAttributeSet getInputAttributes()
Returns the current input attributes. These are automatically set on any newly inserted content, if not specified otherwise.

Returns: the current input attributes

getViewFactory

public ViewFactory getViewFactory()
Returns a {@link ViewFactory} that is able to create {@link View}s for {@link Element}s that are supported by this EditorKit, namely the following types of Elements:

Returns: a {@link ViewFactory} that is able to create {@link View}s for {@link Element}s that are supported by this EditorKit

install

public void install(JEditorPane component)
Installs this EditorKit on the specified {@link JEditorPane}. This basically involves setting up required listeners on the JEditorPane.

Parameters: component the JEditorPane to install this EditorKit on