All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----com.roguewave.format.TextAlignment
A TextAlignment object has three fields: left, center, and right. With one or more of these fields set, the TextAlignment object will provide padding to justify the text in a field of a given width.
The TextAlignment class has four constructors:
public TextAlignment(String left, String center, String right, int width) public TextAlignment(String left, String center, String right) public TextAlignment(String string, int alignment, int width) public TextAlignment(String string, int alignment)For the first two, each field is assigned either a string value (possibly the empty string "") or a null. Fields given a null value indicate where padding should occur. If no null fields are specified then padding will occur to either side of the center field. The next two constructors provide a simplified way to specify a layout with only one field. The first and third specify a width and are expected to be used with the toString() method, while the second and fourth do not, and are intended for use with the toString(int width) method. The alignment argument can have one of three values defined in the TextAlignment class: LEFT, CENTER, and RIGHT.
Here are the various permutations and the resulting output:
|<------ width ------>| |left center right| (left, center, right, width) |leftcenter | (left, center, null, width) |left | (left, null, null, width) | center | (null, center, null, width)| | centerright| (null, center, right, width) |left right| (left, null, right, width) | right| (null, null, right, width) |leftcenterright (left, center, right, i) i < "leftcenterright".length()The TextAlignmentExample.java example program prints out something similar to the above. Another example, TextAlignmentExample2.java, combines use of TextPicture and TextAlignment to produce this output:
---------------------------------------------------------------------------- | Attribute | Type | Default | Description | |----------------|---------|---------|-------------------------------------| | decimalSymbol | String | . | what to print at the decimal point | | width | int | 0 | width to pad to | | leftPadChar | char | <space> | char to use for left padding | ----------------------------------------------------------------------------
public static final int LEFTRIGHT
public static final int RIGHTCENTER
public static final int CENTER
public TextAlignment(String left, String center, String right, int width)
public TextAlignment(String left, String center, String right)
public TextAlignment(String string, int alignment)
public TextAlignment(String string, int alignment, int width)
public void setPadChar(char c)
public String toString()
public void setWidth(int width)
public String toString(int width)
All Packages Class Hierarchy This Package Previous Next Index