Determining If a Style Attribute Applies to a Character or the Paragraph - Java Swing

Java examples for Swing:JTextPane

Description

Determining If a Style Attribute Applies to a Character or the Paragraph

Demo Code

import javax.swing.text.AttributeSet;
import javax.swing.text.StyleConstants;

public class Main {
  public static void main(String[] argv) {
    boolean b;//from w w  w .ja  v a 2s . co m

    // 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
  }
}

Related Tutorials