Java Reference
In-Depth Information
Creating a SimpleAttributeSet
SimpleAttributeSet has two constructors:
public SimpleAttributeSet()
SimpleAttributeSet attributeSet1 = new SimpleAttributeSet();
public SimpleAttributeSet(AttributeSet source)
SimpleAttributeSet attributeSet2 = new SimpleAttributeSet(attributeSet1);
You would typically create an empty SimpleAttributeSet , and then set its attributes, as
in the first constructor listed. Or, you can instead provide the initial settings for the set of
attributes in the constructor. Note that this is not the resolving parent—it's just an initialized
data structure.
SimpleAttributeSet Properties
Table 16-3 displays the four properties of SimpleAttributeSet . They provide access to the set of
attributes, let you know whether any attributes exist, and identify the resolving parent (if any).
Table 16-3. SimpleAttributeSet Properties
Property Name
Data Type
Access
attributeCount
int
Read-only
attributeNames
Enumeration
Read-only
empty
boolean
Read-only
resolveParent
AttributeSet
Read-write
Using a SimpleAttributeSet
To create an appropriate AttributeSet to use with a SimpleAttributeSet , you need to discover
the keys for the attributes you want to alter. You'll see some helper methods shortly in the
StyleConstants class covered in the next section. All the keys are hidden away in four public
inner classes of StyleConstants : CharacterConstants , ColorConstants , FontConstants , and
ParagraphConstants , as shown in Table 16-4.
Table 16-4. Key Constants for Storing AttributeSet Values
AttributeSet Key Constants
Value Type
Default Setting
CharacterConstants.Background
Color
Color.BLACK
ColorConstants.Background
Color
Color.BLACK
CharacterConstants.BidiLevel
Integer
0
CharacterConstants.Bold
Boolean
false
FontConstants.Bold
Boolean
false
 
Search WWH ::




Custom Search