TabStop
Inheritance: java.lang.Object
All Implemented Interfaces: java.lang.Cloneable
public class TabStop implements Cloneable
Represents a single custom tab stop. The TabStop object is a member of the TabStopCollection collection.
To learn more, visit the Aspose.Words Document Object Model (DOM) documentation article.
Remarks:
Normally, a tab stop specifies a position where a tab stop exists. But because tab stops can be inherited from parent styles, it might be needed for the child object to define explicitly that there is no tab stop at a given position. To clear an inherited tab stop at a given position, create a TabStop object and set getAlignment() / setAlignment(int) to TabAlignment.CLEAR.
For more information see TabStopCollection.
Examples:
Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (Paragraph para : (Iterable) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
&& para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
TabStop tab = para.getParagraphFormat().getTabStops().get(0);
// Replace the first default tab, stop with a custom tab stop.
para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50.0, tab.getAlignment(), tab.getLeader());
}
}
doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
Constructors
Constructor | Description |
---|---|
TabStop(double position) | Initializes a new instance of this class. |
TabStop(double position, int alignment, int leader) | Initializes a new instance of this class. |
Methods
Method | Description |
---|---|
equals(TabStop rhs) | Compares with the specified TabStop. |
getAlignment() | Gets the alignment of text at this tab stop. |
getLeader() | Gets the type of the leader line displayed under the tab character. |
getPosition() | Gets the position of the tab stop in points. |
hashCode() | |
isClear() | Returns true if this tab stop clears any existing tab stops in this position. |
setAlignment(int value) | Sets the alignment of text at this tab stop. |
setLeader(int value) | Sets the type of the leader line displayed under the tab character. |
TabStop(double position)
public TabStop(double position)
Initializes a new instance of this class.
Examples:
Shows how to work with a document’s collection of tab stops.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES));
Assert.assertEquals(2, tabStops.getCount());
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder.writeln("Start\tTab 1\tTab 2");
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(2, paragraphs.getCount());
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
// A tab stop collection can point us to TabStops before and after certain positions.
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs.get(1).getParagraphFormat().getTabStops().clear();
Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount());
doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
Parameters:
Parameter | Type | Description |
---|---|---|
position | double |
TabStop(double position, int alignment, int leader)
public TabStop(double position, int alignment, int leader)
Initializes a new instance of this class.
Parameters:
Parameter | Type | Description |
---|---|---|
position | double | |
alignment | int | |
leader | int |
equals(TabStop rhs)
public boolean equals(TabStop rhs)
Compares with the specified TabStop.
Examples:
Shows how to work with a document’s collection of tab stops.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES));
Assert.assertEquals(2, tabStops.getCount());
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder.writeln("Start\tTab 1\tTab 2");
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(2, paragraphs.getCount());
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
// A tab stop collection can point us to TabStops before and after certain positions.
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs.get(1).getParagraphFormat().getTabStops().clear();
Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount());
doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
Parameters:
Parameter | Type | Description |
---|---|---|
rhs | TabStop |
Returns: boolean
getAlignment()
public int getAlignment()
Gets the alignment of text at this tab stop.
Examples:
Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (Paragraph para : (Iterable) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
&& para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
TabStop tab = para.getParagraphFormat().getTabStops().get(0);
// Replace the first default tab, stop with a custom tab stop.
para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50.0, tab.getAlignment(), tab.getLeader());
}
}
doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
Returns: int - The alignment of text at this tab stop. The returned value is one of TabAlignment constants.
getLeader()
public int getLeader()
Gets the type of the leader line displayed under the tab character.
Examples:
Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (Paragraph para : (Iterable) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
&& para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
TabStop tab = para.getParagraphFormat().getTabStops().get(0);
// Replace the first default tab, stop with a custom tab stop.
para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50.0, tab.getAlignment(), tab.getLeader());
}
}
doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
Returns: int - The type of the leader line displayed under the tab character. The returned value is one of TabLeader constants.
getPosition()
public double getPosition()
Gets the position of the tab stop in points.
Examples:
Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (Paragraph para : (Iterable) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
&& para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
TabStop tab = para.getParagraphFormat().getTabStops().get(0);
// Replace the first default tab, stop with a custom tab stop.
para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50.0, tab.getAlignment(), tab.getLeader());
}
}
doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
Returns: double - The position of the tab stop in points.
hashCode()
public int hashCode()
Returns: int
isClear()
public boolean isClear()
Returns true if this tab stop clears any existing tab stops in this position.
Examples:
Shows how to work with a document’s collection of tab stops.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();
// 72 points is one "inch" on the Microsoft Word tab stop ruler.
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432, TabAlignment.RIGHT, TabLeader.DASHES));
Assert.assertEquals(2, tabStops.getCount());
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));
// Every "tab" character takes the builder's cursor to the location of the next tab stop.
builder.writeln("Start\tTab 1\tTab 2");
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(2, paragraphs.getCount());
// Each paragraph gets its tab stop collection, which clones its values from the document builder's tab stop collection.
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
// A tab stop collection can point us to TabStops before and after certain positions.
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());
// We can clear a paragraph's tab stop collection to revert to the default tabbing behavior.
paragraphs.get(1).getParagraphFormat().getTabStops().clear();
Assert.assertEquals(0, paragraphs.get(1).getParagraphFormat().getTabStops().getCount());
doc.save(getArtifactsDir() + "TabStopCollection.TabStopCollection.docx");
Returns: boolean - true if this tab stop clears any existing tab stops in this position.
setAlignment(int value)
public void setAlignment(int value)
Sets the alignment of text at this tab stop.
Examples:
Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (Paragraph para : (Iterable) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
&& para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
TabStop tab = para.getParagraphFormat().getTabStops().get(0);
// Replace the first default tab, stop with a custom tab stop.
para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50.0, tab.getAlignment(), tab.getLeader());
}
}
doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | The alignment of text at this tab stop. The value must be one of TabAlignment constants. |
setLeader(int value)
public void setLeader(int value)
Sets the type of the leader line displayed under the tab character.
Examples:
Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (Paragraph para : (Iterable) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
&& para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
TabStop tab = para.getParagraphFormat().getTabStops().get(0);
// Replace the first default tab, stop with a custom tab stop.
para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50.0, tab.getAlignment(), tab.getLeader());
}
}
doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | The type of the leader line displayed under the tab character. The value must be one of TabLeader constants. |