e1014. determining if a style attribute applies to a character or the paragraph.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 21 行

TXT
21
字号
All style attributes as defined in StyleConstants are either character- or paragraph-based attributes. See also e1010 Listing the Attributes in a Style. 
    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

It is also possible to determine if the attribute is a color or a font-related attribute. 
    // 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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?