Using StyleConstants class to simplify style sttribute settings : SimpleAttributeSet « Swing « Java Tutorial






  1. The StyleConstants class is full of helper methods to simplify setting attribute sets.
  2. Instead of calling the following to make the SimpleAttributeSet both bold and italic:
attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE)
attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE)

You could use the following:

StyleConstants.setBold(attributes, true);
StyleConstants.setItalic(attributes, true);








14.39.SimpleAttributeSet
14.39.1.Creating Styled Text: Using a SimpleAttributeSet
14.39.2.Using StyleConstants class to simplify style sttribute settings
14.39.3.Add colored text to the document
14.39.4.Use SimpleAttributeSet with JTextPane
14.39.5.Tests two attributed strings for equality.