javax.swing.text

Class StyleConstants

public class StyleConstants extends Object

Represents standard attribute keys. This class also contains a set of useful static utility methods for querying and populating an {@link AttributeSet}.

Since: 1.2

Nested Class Summary
static classStyleConstants.CharacterConstants
A set of keys for attributes that apply to characters.
static classStyleConstants.ColorConstants
A set of keys for attributes that relate to colors.
static classStyleConstants.FontConstants
A set of keys for attributes that apply to fonts.
static classStyleConstants.ParagraphConstants
A set of keys for attributes that apply to paragraphs.
Field Summary
static ObjectAlignment
An alias for {@link ParagraphConstants#Alignment}.
static intALIGN_CENTER
A value representing center alignment for the {@link ParagraphConstants#Alignment} attribute.
static intALIGN_JUSTIFIED
A value representing ful justification for the {@link ParagraphConstants#Alignment} attribute.
static intALIGN_LEFT
A value representing left alignment for the {@link ParagraphConstants#Alignment} attribute.
static intALIGN_RIGHT
A value representing right alignment for the {@link ParagraphConstants#Alignment} attribute.
static ObjectBackground
An alias for {@link CharacterConstants#Background}.
static ObjectBidiLevel
An alias for {@link CharacterConstants#BidiLevel}.
static ObjectBold
An alias for {@link CharacterConstants#Bold}.
static ObjectComponentAttribute
An alias for {@link CharacterConstants#ComponentAttribute}.
static StringComponentElementName
static ObjectComposedTextAttribute
static ObjectFamily
An alias for {@link CharacterConstants#Family}.
static ObjectFirstLineIndent
An alias for {@link ParagraphConstants#FirstLineIndent}.
static ObjectFontFamily
An alias for {@link CharacterConstants#Family}.
static ObjectFontSize
An alias for {@link CharacterConstants#Size}.
static ObjectForeground
An alias for {@link CharacterConstants#Foreground}.
static ObjectIconAttribute
An alias for {@link CharacterConstants#IconAttribute}.
static StringIconElementName
static ObjectItalic
An alias for {@link CharacterConstants#Italic}.
static ObjectLeftIndent
An alias for {@link ParagraphConstants#LeftIndent}.
static ObjectLineSpacing
An alias for {@link ParagraphConstants#LineSpacing}.
static ObjectModelAttribute
static ObjectNameAttribute
static ObjectOrientation
An alias for {@link ParagraphConstants#Orientation}.
static ObjectResolveAttribute
static ObjectRightIndent
An alias for {@link ParagraphConstants#RightIndent}.
static ObjectSize
An alias for {@link CharacterConstants#Size}.
static ObjectSpaceAbove
An alias for {@link ParagraphConstants#SpaceAbove}.
static ObjectSpaceBelow
An alias for {@link ParagraphConstants#SpaceBelow}.
static ObjectStrikeThrough
An alias for {@link CharacterConstants#StrikeThrough}.
static ObjectSubscript
An alias for {@link CharacterConstants#Subscript}.
static ObjectSuperscript
An alias for {@link CharacterConstants#Superscript}.
static ObjectTabSet
An alias for {@link ParagraphConstants#TabSet}.
static ObjectUnderline
An alias for {@link CharacterConstants#Underline}.
Method Summary
static intgetAlignment(AttributeSet a)
Returns the alignment specified in the given attributes, or {@link #ALIGN_LEFT} if no alignment is specified.
static ColorgetBackground(AttributeSet a)
Returns the background color specified in the given attributes, or {@link Color#BLACK} if no background color is specified.
static intgetBidiLevel(AttributeSet a)
Returns the bidi level specified in the given attributes, or 0 if no bidi level is specified.
static ComponentgetComponent(AttributeSet a)
Returns the component specified in the given attributes, or null if no component is specified.
static floatgetFirstLineIndent(AttributeSet a)
Returns the indentation specified in the given attributes, or 0.0f if no indentation is specified.
static StringgetFontFamily(AttributeSet a)
Returns the font family specified in the given attributes, or Monospaced if no font family is specified.
static intgetFontSize(AttributeSet a)
Returns the font size specified in the given attributes, or 12 if no font size is specified.
static ColorgetForeground(AttributeSet a)
Returns the foreground color specified in the given attributes, or {@link Color#BLACK} if no foreground color is specified.
static IcongetIcon(AttributeSet a)
Returns the icon specified in the given attributes, or null if no icon is specified.
static floatgetLeftIndent(AttributeSet a)
Returns the left indentation specified in the given attributes, or 0.0f if no left indentation is specified.
static floatgetLineSpacing(AttributeSet a)
Returns the line spacing specified in the given attributes, or 0.0f if no line spacing is specified.
static floatgetRightIndent(AttributeSet a)
Returns the right indentation specified in the given attributes, or 0.0f if no right indentation is specified.
static floatgetSpaceAbove(AttributeSet a)
Returns the 'space above' specified in the given attributes, or 0.0f if no 'space above' is specified.
static floatgetSpaceBelow(AttributeSet a)
Returns the 'space below' specified in the given attributes, or 0.0f if no 'space below' is specified.
static TabSetgetTabSet(AttributeSet a)
Returns the tab set specified in the given attributes, or null if no tab set is specified.
static booleanisBold(AttributeSet a)
Returns the value of the bold flag in the given attributes, or false if no bold flag is specified.
static booleanisItalic(AttributeSet a)
Returns the value of the italic flag in the given attributes, or false if no italic flag is specified.
static booleanisStrikeThrough(AttributeSet a)
Returns the value of the strike-through flag in the given attributes, or false if no strike-through flag is specified.
static booleanisSubscript(AttributeSet a)
Returns the value of the subscript flag in the given attributes, or false if no subscript flag is specified.
static booleanisSuperscript(AttributeSet a)
Returns the value of the superscript flag in the given attributes, or false if no superscript flag is specified.
static booleanisUnderline(AttributeSet a)
Returns the value of the underline flag in the given attributes, or false if no underline flag is specified.
static voidsetAlignment(MutableAttributeSet a, int align)
Adds an alignment attribute to the specified set.
static voidsetBackground(MutableAttributeSet a, Color bg)
Adds a background attribute to the specified set.
static voidsetBidiLevel(MutableAttributeSet a, int lev)
Adds a bidi-level attribute to the specified set.
static voidsetBold(MutableAttributeSet a, boolean b)
Adds a bold attribute to the specified set.
static voidsetComponent(MutableAttributeSet a, Component c)
Adds a component attribute to the specified set.
static voidsetFirstLineIndent(MutableAttributeSet a, float i)
Adds a first line indentation attribute to the specified set.
static voidsetFontFamily(MutableAttributeSet a, String fam)
Adds a font family attribute to the specified set.
static voidsetFontSize(MutableAttributeSet a, int s)
Adds a font size attribute to the specified set.
static voidsetForeground(MutableAttributeSet a, Color fg)
Adds a foreground color attribute to the specified set.
static voidsetIcon(MutableAttributeSet a, Icon c)
Adds an icon attribute to the specified set.
static voidsetItalic(MutableAttributeSet a, boolean b)
Adds an italic attribute to the specified set.
static voidsetLeftIndent(MutableAttributeSet a, float i)
Adds a left indentation attribute to the specified set.
static voidsetLineSpacing(MutableAttributeSet a, float i)
Adds a line spacing attribute to the specified set.
static voidsetRightIndent(MutableAttributeSet a, float i)
Adds a right indentation attribute to the specified set.
static voidsetSpaceAbove(MutableAttributeSet a, float i)
Adds a 'space above' attribute to the specified set.
static voidsetSpaceBelow(MutableAttributeSet a, float i)
Adds a 'space below' attribute to the specified set.
static voidsetStrikeThrough(MutableAttributeSet a, boolean b)
Adds a strike-through attribue to the specified set.
static voidsetSubscript(MutableAttributeSet a, boolean b)
Adds a subscript attribute to the specified set.
static voidsetSuperscript(MutableAttributeSet a, boolean b)
Adds a superscript attribute to the specified set.
static voidsetTabSet(MutableAttributeSet a, TabSet tabs)
Adds a {@link TabSet} attribute to the specified set.
static voidsetUnderline(MutableAttributeSet a, boolean b)
Adds an underline attribute to the specified set.
StringtoString()
Returns a string representation of the attribute key.

Field Detail

Alignment

public static final Object Alignment
An alias for {@link ParagraphConstants#Alignment}.

ALIGN_CENTER

public static final int ALIGN_CENTER
A value representing center alignment for the {@link ParagraphConstants#Alignment} attribute.

ALIGN_JUSTIFIED

public static final int ALIGN_JUSTIFIED
A value representing ful justification for the {@link ParagraphConstants#Alignment} attribute.

ALIGN_LEFT

public static final int ALIGN_LEFT
A value representing left alignment for the {@link ParagraphConstants#Alignment} attribute.

ALIGN_RIGHT

public static final int ALIGN_RIGHT
A value representing right alignment for the {@link ParagraphConstants#Alignment} attribute.

Background

public static final Object Background
An alias for {@link CharacterConstants#Background}.

BidiLevel

public static final Object BidiLevel
An alias for {@link CharacterConstants#BidiLevel}.

Bold

public static final Object Bold
An alias for {@link CharacterConstants#Bold}.

ComponentAttribute

public static final Object ComponentAttribute
An alias for {@link CharacterConstants#ComponentAttribute}.

ComponentElementName

public static final String ComponentElementName

ComposedTextAttribute

public static final Object ComposedTextAttribute

Family

public static final Object Family
An alias for {@link CharacterConstants#Family}.

FirstLineIndent

public static final Object FirstLineIndent
An alias for {@link ParagraphConstants#FirstLineIndent}.

FontFamily

public static final Object FontFamily
An alias for {@link CharacterConstants#Family}.

FontSize

public static final Object FontSize
An alias for {@link CharacterConstants#Size}.

Foreground

public static final Object Foreground
An alias for {@link CharacterConstants#Foreground}.

IconAttribute

public static final Object IconAttribute
An alias for {@link CharacterConstants#IconAttribute}.

IconElementName

public static final String IconElementName

Italic

public static final Object Italic
An alias for {@link CharacterConstants#Italic}.

LeftIndent

public static final Object LeftIndent
An alias for {@link ParagraphConstants#LeftIndent}.

LineSpacing

public static final Object LineSpacing
An alias for {@link ParagraphConstants#LineSpacing}.

ModelAttribute

public static final Object ModelAttribute

NameAttribute

public static final Object NameAttribute

Orientation

public static final Object Orientation
An alias for {@link ParagraphConstants#Orientation}.

ResolveAttribute

public static final Object ResolveAttribute

RightIndent

public static final Object RightIndent
An alias for {@link ParagraphConstants#RightIndent}.

Size

public static final Object Size
An alias for {@link CharacterConstants#Size}.

SpaceAbove

public static final Object SpaceAbove
An alias for {@link ParagraphConstants#SpaceAbove}.

SpaceBelow

public static final Object SpaceBelow
An alias for {@link ParagraphConstants#SpaceBelow}.

StrikeThrough

public static final Object StrikeThrough
An alias for {@link CharacterConstants#StrikeThrough}.

Subscript

public static final Object Subscript
An alias for {@link CharacterConstants#Subscript}.

Superscript

public static final Object Superscript
An alias for {@link CharacterConstants#Superscript}.

TabSet

public static final Object TabSet
An alias for {@link ParagraphConstants#TabSet}.

Underline

public static final Object Underline
An alias for {@link CharacterConstants#Underline}.

Method Detail

getAlignment

public static int getAlignment(AttributeSet a)
Returns the alignment specified in the given attributes, or {@link #ALIGN_LEFT} if no alignment is specified.

Parameters: a the attribute set (null not permitted).

Returns: The alignment (typically one of {@link #ALIGN_LEFT}, {@link #ALIGN_RIGHT}, {@link #ALIGN_CENTER} or {@link #ALIGN_JUSTIFIED}).

See Also: StyleConstants

getBackground

public static Color getBackground(AttributeSet a)
Returns the background color specified in the given attributes, or {@link Color#BLACK} if no background color is specified.

Parameters: a the attribute set (null not permitted).

Returns: The background color.

See Also: StyleConstants

getBidiLevel

public static int getBidiLevel(AttributeSet a)
Returns the bidi level specified in the given attributes, or 0 if no bidi level is specified.

Parameters: a the attribute set (null not permitted).

Returns: The bidi level.

See Also: StyleConstants

getComponent

public static Component getComponent(AttributeSet a)
Returns the component specified in the given attributes, or null if no component is specified.

Parameters: a the attribute set (null not permitted).

Returns: The component (possibly null).

See Also: StyleConstants

getFirstLineIndent

public static float getFirstLineIndent(AttributeSet a)
Returns the indentation specified in the given attributes, or 0.0f if no indentation is specified.

Parameters: a the attribute set (null not permitted).

Returns: The indentation.

See Also: StyleConstants

getFontFamily

public static String getFontFamily(AttributeSet a)
Returns the font family specified in the given attributes, or Monospaced if no font family is specified.

Parameters: a the attribute set (null not permitted).

Returns: The font family.

See Also: StyleConstants

getFontSize

public static int getFontSize(AttributeSet a)
Returns the font size specified in the given attributes, or 12 if no font size is specified.

Parameters: a the attribute set (null not permitted).

Returns: The font size.

See Also: StyleConstants

getForeground

public static Color getForeground(AttributeSet a)
Returns the foreground color specified in the given attributes, or {@link Color#BLACK} if no foreground color is specified.

Parameters: a the attribute set (null not permitted).

Returns: The foreground color.

See Also: StyleConstants

getIcon

public static Icon getIcon(AttributeSet a)
Returns the icon specified in the given attributes, or null if no icon is specified.

Parameters: a the attribute set (null not permitted).

Returns: The icon (possibly null).

See Also: StyleConstants

getLeftIndent

public static float getLeftIndent(AttributeSet a)
Returns the left indentation specified in the given attributes, or 0.0f if no left indentation is specified.

Parameters: a the attribute set (null not permitted).

Returns: The left indentation.

See Also: StyleConstants

getLineSpacing

public static float getLineSpacing(AttributeSet a)
Returns the line spacing specified in the given attributes, or 0.0f if no line spacing is specified.

Parameters: a the attribute set (null not permitted).

Returns: The line spacing.

See Also: StyleConstants

getRightIndent

public static float getRightIndent(AttributeSet a)
Returns the right indentation specified in the given attributes, or 0.0f if no right indentation is specified.

Parameters: a the attribute set (null not permitted).

Returns: The right indentation.

See Also: StyleConstants

getSpaceAbove

public static float getSpaceAbove(AttributeSet a)
Returns the 'space above' specified in the given attributes, or 0.0f if no 'space above' is specified.

Parameters: a the attribute set (null not permitted).

Returns: The 'space above'.

See Also: StyleConstants

getSpaceBelow

public static float getSpaceBelow(AttributeSet a)
Returns the 'space below' specified in the given attributes, or 0.0f if no 'space below' is specified.

Parameters: a the attribute set (null not permitted).

Returns: The 'space below'.

See Also: StyleConstants

getTabSet

public static TabSet getTabSet(AttributeSet a)
Returns the tab set specified in the given attributes, or null if no tab set is specified.

Parameters: a the attribute set (null not permitted).

Returns: The tab set.

See Also: StyleConstants

isBold

public static boolean isBold(AttributeSet a)
Returns the value of the bold flag in the given attributes, or false if no bold flag is specified.

Parameters: a the attribute set (null not permitted).

Returns: The bold flag.

See Also: StyleConstants

isItalic

public static boolean isItalic(AttributeSet a)
Returns the value of the italic flag in the given attributes, or false if no italic flag is specified.

Parameters: a the attribute set (null not permitted).

Returns: The italic flag.

See Also: StyleConstants

isStrikeThrough

public static boolean isStrikeThrough(AttributeSet a)
Returns the value of the strike-through flag in the given attributes, or false if no strike-through flag is specified.

Parameters: a the attribute set (null not permitted).

Returns: The strike-through flag.

See Also: StyleConstants

isSubscript

public static boolean isSubscript(AttributeSet a)
Returns the value of the subscript flag in the given attributes, or false if no subscript flag is specified.

Parameters: a the attribute set (null not permitted).

Returns: The subscript flag.

See Also: StyleConstants

isSuperscript

public static boolean isSuperscript(AttributeSet a)
Returns the value of the superscript flag in the given attributes, or false if no superscript flag is specified.

Parameters: a the attribute set (null not permitted).

Returns: The superscript flag.

See Also: StyleConstants

isUnderline

public static boolean isUnderline(AttributeSet a)
Returns the value of the underline flag in the given attributes, or false if no underline flag is specified.

Parameters: a the attribute set (null not permitted).

Returns: The underline flag.

See Also: StyleConstants

setAlignment

public static void setAlignment(MutableAttributeSet a, int align)
Adds an alignment attribute to the specified set.

Parameters: a the attribute set (null not permitted). align the alignment (typically one of {@link StyleConstants#ALIGN_LEFT}, {@link StyleConstants#ALIGN_RIGHT}, {@link StyleConstants#ALIGN_CENTER} or {@link StyleConstants#ALIGN_JUSTIFIED}).

Throws: NullPointerException if a is null.

See Also: getAlignment

setBackground

public static void setBackground(MutableAttributeSet a, Color bg)
Adds a background attribute to the specified set.

Parameters: a the attribute set (null not permitted). bg the background (null not permitted).

Throws: NullPointerException if either argument is null.

See Also: getBackground

setBidiLevel

public static void setBidiLevel(MutableAttributeSet a, int lev)
Adds a bidi-level attribute to the specified set.

Parameters: a the attribute set (null not permitted). lev the level.

Throws: NullPointerException if a is null.

See Also: getBidiLevel

setBold

public static void setBold(MutableAttributeSet a, boolean b)
Adds a bold attribute to the specified set.

Parameters: a the attribute set (null not permitted). b the new value of the bold attribute.

Throws: NullPointerException if a is null.

See Also: isBold

setComponent

public static void setComponent(MutableAttributeSet a, Component c)
Adds a component attribute to the specified set.

Parameters: a the attribute set (null not permitted). c the component (null not permitted).

Throws: NullPointerException if either argument is null.

See Also: getComponent

setFirstLineIndent

public static void setFirstLineIndent(MutableAttributeSet a, float i)
Adds a first line indentation attribute to the specified set.

Parameters: a the attribute set (null not permitted). i the indentation.

Throws: NullPointerException if a is null.

See Also: getFirstLineIndent

setFontFamily

public static void setFontFamily(MutableAttributeSet a, String fam)
Adds a font family attribute to the specified set.

Parameters: a the attribute set (null not permitted). fam the font family name (null not permitted).

Throws: NullPointerException if either argument is null.

See Also: getFontFamily

setFontSize

public static void setFontSize(MutableAttributeSet a, int s)
Adds a font size attribute to the specified set.

Parameters: a the attribute set (null not permitted). s the font size (in points).

Throws: NullPointerException if a is null.

See Also: getFontSize

setForeground

public static void setForeground(MutableAttributeSet a, Color fg)
Adds a foreground color attribute to the specified set.

Parameters: a the attribute set (null not permitted). fg the foreground color (null not permitted).

Throws: NullPointerException if either argument is null.

See Also: getForeground

setIcon

public static void setIcon(MutableAttributeSet a, Icon c)
Adds an icon attribute to the specified set.

Parameters: a the attribute set (null not permitted). c the icon (null not permitted).

Throws: NullPointerException if either argument is null.

See Also: getIcon

setItalic

public static void setItalic(MutableAttributeSet a, boolean b)
Adds an italic attribute to the specified set.

Parameters: a the attribute set (null not permitted). b the new value of the italic attribute.

Throws: NullPointerException if a is null.

See Also: isItalic

setLeftIndent

public static void setLeftIndent(MutableAttributeSet a, float i)
Adds a left indentation attribute to the specified set.

Parameters: a the attribute set (null not permitted). i the indentation.

Throws: NullPointerException if a is null.

See Also: getLeftIndent

setLineSpacing

public static void setLineSpacing(MutableAttributeSet a, float i)
Adds a line spacing attribute to the specified set.

Parameters: a the attribute set (null not permitted). i the line spacing.

Throws: NullPointerException if a is null.

See Also: getLineSpacing

setRightIndent

public static void setRightIndent(MutableAttributeSet a, float i)
Adds a right indentation attribute to the specified set.

Parameters: a the attribute set (null not permitted). i the right indentation.

Throws: NullPointerException if a is null.

See Also: getRightIndent

setSpaceAbove

public static void setSpaceAbove(MutableAttributeSet a, float i)
Adds a 'space above' attribute to the specified set.

Parameters: a the attribute set (null not permitted). i the space above attribute value.

Throws: NullPointerException if a is null.

See Also: getSpaceAbove

setSpaceBelow

public static void setSpaceBelow(MutableAttributeSet a, float i)
Adds a 'space below' attribute to the specified set.

Parameters: a the attribute set (null not permitted). i the space below attribute value.

Throws: NullPointerException if a is null.

See Also: getSpaceBelow

setStrikeThrough

public static void setStrikeThrough(MutableAttributeSet a, boolean b)
Adds a strike-through attribue to the specified set.

Parameters: a the attribute set (null not permitted). b the strike-through attribute value.

Throws: NullPointerException if a is null.

See Also: isStrikeThrough

setSubscript

public static void setSubscript(MutableAttributeSet a, boolean b)
Adds a subscript attribute to the specified set.

Parameters: a the attribute set (null not permitted). b the subscript attribute value.

Throws: NullPointerException if a is null.

See Also: isSubscript

setSuperscript

public static void setSuperscript(MutableAttributeSet a, boolean b)
Adds a superscript attribute to the specified set.

Parameters: a the attribute set (null not permitted). b the superscript attribute value.

Throws: NullPointerException if a is null.

See Also: isSuperscript

setTabSet

public static void setTabSet(MutableAttributeSet a, TabSet tabs)
Adds a {@link TabSet} attribute to the specified set.

Parameters: a the attribute set (null not permitted). tabs the tab set (null not permitted).

Throws: NullPointerException if either argument is null.

See Also: getTabSet

setUnderline

public static void setUnderline(MutableAttributeSet a, boolean b)
Adds an underline attribute to the specified set.

Parameters: a the attribute set (null not permitted). b the underline attribute value.

Throws: NullPointerException if a is null.

See Also: isUnderline

toString

public String toString()
Returns a string representation of the attribute key.

Returns: A string representation of the attribute key.