Determining If a Style Attribute Applies to a Character or the Paragraph
All style attributes as defined in StyleConstants are either
character- or paragraph-based attributes. See also
Listing the Attributes in a Style.
It is also possible to determine if the attribute is a color or a
font-related attribute.
boolean b;
// Check if character-based attribute
b = StyleConstants.Italic instanceof AttributeSet.CharacterAttribute; // true
b = StyleConstants.LineSpacing instanceof AttributeSet.CharacterAttribute; // false
// Check if paragraph-based attribute
b = StyleConstants.LineSpacing instanceof AttributeSet.ParagraphAttribute; // true
b = StyleConstants.Italic instanceof AttributeSet.ParagraphAttribute; // false
// Check if color-based attribute
b = StyleConstants.Foreground instanceof AttributeSet.ColorAttribute; // true
b = StyleConstants.Italic instanceof AttributeSet.ColorAttribute; // false
// Check if font-based attribute
b = StyleConstants.Italic instanceof AttributeSet.FontAttribute; // true
b = StyleConstants.Foreground instanceof AttributeSet.FontAttribute; // false
Post a comment