Java Reference
In-Depth Information
public static void setLineSpacing(MutableAttributeSet a, float i);
public static void setRightIndent(MutableAttributeSet a, float i);
public static void setSpaceAbove(MutableAttributeSet a, float i);
public static void setSpaceBelow(MutableAttributeSet a, float i);
public static void setStrikeThrough(MutableAttributeSet a, boolean b);
public static void setSubscript(MutableAttributeSet a, boolean b);
public static void setSuperscript(MutableAttributeSet a, boolean b);
public static void setTabSet(MutableAttributeSet a, TabSet tabs);
public static void setUnderline(MutableAttributeSet a, boolean b);
For instance, 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);
As you can see, the latter form is much more readable and easier to maintain!
Tip Besides methods to change AttributeSet objects, the StyleConstants class provides many
other methods that let you check the status of an AttributeSet to see if a setting is currently enabled
or disabled.
TabStop and TabSet Classes
One of the key constants for storing AttributeSet values is the ParagraphConstants.TabSet
attribute. The TabSet class represents a collection of TabStop objects, each defining a tab position,
alignment, and leader. If you wanted to define your own tab stops for a JTextPane , you could
create a set of TabStop objects, one for each tab stop, create the TabSet , and then associate the
TabSet with a MutableAttributeSet .
Creating a TabStop
The TabStop class isn't a JavaBean component in the typical sense; it does not have a no-argument
constructor. Instead, you must specify the position, in pixels, at which to place the tab stop.
It has two constructors:
public TabStop(float position)
TabStop stop = new TabStop(40);
public TabStop(float position, int align, int leader)
TabStop stop = new TabStop(40, TabStop.ALIGN_DECIMAL, TabStop.LEAD_DOTS);
 
Search WWH ::




Custom Search