APIdia Launch Partner
Top Description Fields Methods
javax.swing.text

public Interface StyledDocument

extends Document
Known Direct Implementers
javax.swing.text.DefaultStyledDocument
Imports
java.awt.Font, .Color

Interface for a generic styled document.
Author
Timothy Prinzing

Field Summary

Inherited from javax.swing.text.Document:
StreamDescriptionPropertyTitleProperty

Method Summary

Modifier and TypeMethod and Description
public Style

Returns:

the style
addStyle
(String
the name of the style (must be unique within the collection of named styles). The name may be 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.
nm
,
Style
the parent style. This may be null if unspecified attributes need not be resolved in some other style.
parent
)

Adds a new style into the logical style hierarchy.

public Color

Returns:

the color
getBackground
(AttributeSet
the set of attributes
attr
)

Takes a set of attributes and turn it into a background color specification.

public Element

Returns:

the element
getCharacterElement
(int
the offset >= 0
pos
)

Gets the element that represents the character that is at the given offset within the document.

public Font

Returns:

the font
getFont
(AttributeSet
the set of attributes
attr
)

Takes a set of attributes and turn it into a font specification.

public Color

Returns:

the color
getForeground
(AttributeSet
the set of attributes
attr
)

Takes a set of attributes and turn it into a foreground color specification.

public Style

Returns:

the style
getLogicalStyle
(int
the position >= 0
p
)

Gets a logical style for a given position in a paragraph.

public Element

Returns:

the element
getParagraphElement
(int
the offset >= 0
pos
)

Gets the element that represents the paragraph that encloses the given offset within the document.

public Style

Returns:

the style
getStyle
(String
the name of the style
nm
)

Fetches a named style previously added.

public void
removeStyle(String
the name of the style to remove
nm
)

Removes a named style previously added to the document.

public void
setCharacterAttributes(int
the start of the change >= 0
offset
,
int
the length of the change >= 0
length
,
AttributeSet
the non-null attributes to change to. Any attributes defined will be applied to the text for the given range.
s
,
boolean
indicates whether or not the previous attributes should be cleared before the new attributes as set. If true, the operation will replace the previous attributes entirely. If false, the new attributes will be merged with the previous attributes.
replace
)

Changes the content element attributes used for the given range of existing content in the document.

public void
setLogicalStyle(int
the starting position >= 0
pos
,
Style
the style to set
s
)

Sets the logical style to use for the paragraph at the given position.

public void
setParagraphAttributes(int
the start of the change >= 0
offset
,
int
the length of the change >= 0
length
,
AttributeSet
the non-null attributes to change to. Any attributes defined will be applied to the text for the given range.
s
,
boolean
indicates whether or not the previous attributes should be cleared before the new attributes are set. If true, the operation will replace the previous attributes entirely. If false, the new attributes will be merged with the previous attributes.
replace
)

Sets paragraph attributes.

Inherited from javax.swing.text.Document:
addDocumentListeneraddUndoableEditListenercreatePositiongetDefaultRootElementgetEndPositiongetLengthgetPropertygetRootElementsgetStartPositiongetTextgetTextinsertStringputPropertyremoveremoveDocumentListenerremoveUndoableEditListenerrender

Method Detail

addStyleback 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.

Parameters
nm:String

the name of the style (must be unique within the collection of named styles). The name may be 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.

parent:Style

the parent style. This may be null if unspecified attributes need not be resolved in some other style.

Returns:Style

the style

getBackgroundback to summary
public Color getBackground(AttributeSet attr)

Takes a set of attributes and turn it into a background color specification. This might be used to specify things like brighter, more hue, etc.

Parameters
attr:AttributeSet

the set of attributes

Returns:Color

the color

getCharacterElementback to summary
public Element getCharacterElement(int pos)

Gets the element that represents the character that is at the given offset within the document.

Parameters
pos:int

the offset >= 0

Returns:Element

the element

getFontback to summary
public Font getFont(AttributeSet attr)

Takes a set of attributes and turn it into a font specification. This can be used to turn things like family, style, size, etc into a font that is available on the system the document is currently being used on.

Parameters
attr:AttributeSet

the set of attributes

Returns:Font

the font

getForegroundback to summary
public Color getForeground(AttributeSet attr)

Takes a set of attributes and turn it into a foreground color specification. This might be used to specify things like brighter, more hue, etc.

Parameters
attr:AttributeSet

the set of attributes

Returns:Color

the color

getLogicalStyleback to summary
public Style getLogicalStyle(int p)

Gets a logical style for a given position in a paragraph.

Parameters
p:int

the position >= 0

Returns:Style

the style

getParagraphElementback to summary
public Element getParagraphElement(int pos)

Gets the element that represents the paragraph that encloses the given offset within the document.

Parameters
pos:int

the offset >= 0

Returns:Element

the element

getStyleback to summary
public Style getStyle(String nm)

Fetches a named style previously added.

Parameters
nm:String

the name of the style

Returns:Style

the style

removeStyleback to summary
public void removeStyle(String nm)

Removes a named style previously added to the document.

Parameters
nm:String

the name of the style to remove

setCharacterAttributesback to summary
public void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)

Changes the content element attributes used for the given range of existing content in the document. All of the attributes defined in the given Attributes argument are applied to the given range. This method can be used to completely remove all content level attributes for the given range by giving an Attributes argument that has no attributes defined and setting replace to true.

Parameters
offset:int

the start of the change >= 0

length:int

the length of the change >= 0

s:AttributeSet

the non-null attributes to change to. Any attributes defined will be applied to the text for the given range.

replace:boolean

indicates whether or not the previous attributes should be cleared before the new attributes as set. If true, the operation will replace the previous attributes entirely. If false, the new attributes will be merged with the previous attributes.

setLogicalStyleback to summary
public void setLogicalStyle(int pos, Style s)

Sets the logical style to use for the paragraph at the given 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 turn may resolve through some hierarchy completely independent of the element hierarchy in the document.

Parameters
pos:int

the starting position >= 0

s:Style

the style to set

setParagraphAttributesback to summary
public void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)

Sets paragraph attributes.

Parameters
offset:int

the start of the change >= 0

length:int

the length of the change >= 0

s:AttributeSet

the non-null attributes to change to. Any attributes defined will be applied to the text for the given range.

replace:boolean

indicates whether or not the previous attributes should be cleared before the new attributes are set. If true, the operation will replace the previous attributes entirely. If false, the new attributes will be merged with the previous attributes.