TabAlignment

Inheritance: java.lang.Object

public class TabAlignment

Specifies the alignment/type of a tab stop.

Examples:

Shows how to set custom tab stops for a paragraph.


 Document doc = new Document();
 Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();

 // If we are in a paragraph with no tab stops in this collection,
 // the cursor will jump 36 points each time we press the Tab key in Microsoft Word.
 Assert.assertEquals(0, doc.getFirstSection().getBody().getFirstParagraph().getEffectiveTabStops().length);

 // We can add custom tab stops in Microsoft Word if we enable the ruler via the "View" tab.
 // Each unit on this ruler is two default tab stops, which is 72 points.
 // We can add custom tab stops programmatically like this.
 TabStopCollection tabStops = doc.getFirstSection().getBody().getFirstParagraph().getParagraphFormat().getTabStops();
 tabStops.add(72.0, TabAlignment.LEFT, TabLeader.DOTS);
 tabStops.add(216.0, TabAlignment.CENTER, TabLeader.DASHES);
 tabStops.add(360.0, TabAlignment.RIGHT, TabLeader.LINE);

 // We can see these tab stops in Microsoft Word by enabling the ruler via "View" -> "Show" -> "Ruler".
 Assert.assertEquals(3, para.getEffectiveTabStops().length);

 // Any tab characters we add will make use of the tab stops on the ruler and may,
 // depending on the tab leader's value, leave a line between the tab departure and arrival destinations.
 para.appendChild(new Run(doc, "\tTab 1\tTab 2\tTab 3"));

 doc.save(getArtifactsDir() + "Paragraph.TabStops.docx");
 

Fields

FieldDescription
BARDraws a vertical bar at the tab stop position.
CENTERCenters the text around the tab stop.
CLEARClears any tab stop in this position.
DECIMALAligns the text at the decimal dot.
LEFTLeft-aligns the text after the tab stop.
LISTThe tab is a delimiter between the number/bullet and text in a list item.
RIGHTRight-aligns the text at the tab stop.
length

Methods

MethodDescription
fromName(String tabAlignmentName)
getName(int tabAlignment)
getValues()
toString(int tabAlignment)

BAR

public static int BAR

Draws a vertical bar at the tab stop position.

CENTER

public static int CENTER

Centers the text around the tab stop.

CLEAR

public static int CLEAR

Clears any tab stop in this position.

DECIMAL

public static int DECIMAL

Aligns the text at the decimal dot.

LEFT

public static int LEFT

Left-aligns the text after the tab stop.

LIST

public static int LIST

The tab is a delimiter between the number/bullet and text in a list item.

public static int RIGHT

Right-aligns the text at the tab stop.

length

public static int length

fromName(String tabAlignmentName)

public static int fromName(String tabAlignmentName)

Parameters:

ParameterTypeDescription
tabAlignmentNamejava.lang.String

Returns: int

getName(int tabAlignment)

public static String getName(int tabAlignment)

Parameters:

ParameterTypeDescription
tabAlignmentint

Returns: java.lang.String

getValues()

public static int[] getValues()

Returns: int[]

toString(int tabAlignment)

public static String toString(int tabAlignment)

Parameters:

ParameterTypeDescription
tabAlignmentint

Returns: java.lang.String