com.aspose.words

Class BorderCollection

  • java.lang.Object
    • com.aspose.words.BorderCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class BorderCollection 
    extends java.lang.Object

A collection of Border objects.
Different document elements have different borders. For example, ParagraphFormat has Bottom, Left, Right and Top borders. You can specify different formatting for each border independently or enumerate through all borders and apply same formatting.

Example:

Inserts a paragraph with a top border.
DocumentBuilder builder = new DocumentBuilder();

Border topBorder = builder.getParagraphFormat().getBorders().getByBorderType(BorderType.TOP);
topBorder.setColor(Color.RED);
topBorder.setLineStyle(LineStyle.DASH_SMALL_GAP);
topBorder.setLineWidth(4);

builder.writeln("Hello World!");

Property Getters/Setters Summary
BordergetBottom()
Gets the bottom border.
java.awt.ColorgetColor()
void
setColor(java.awt.Colorvalue)
           Gets or sets the border color.
intgetCount()
Gets the number of borders in the collection.
doublegetDistanceFromText()
void
setDistanceFromText(doublevalue)
           Gets or sets distance of the border from text in points.
BordergetHorizontal()
Gets the horizontal border that is used between cells or conforming paragraphs.
BordergetLeft()
Gets the left border.
intgetLineStyle()
void
setLineStyle(intvalue)
           Gets or sets the border style. The value of the property is LineStyle integer constant.
doublegetLineWidth()
void
setLineWidth(doublevalue)
           Gets or sets the border width in points.
BordergetRight()
Gets the right border.
booleangetShadow()
void
setShadow(booleanvalue)
           Gets or sets a value indicating whether the border has a shadow.
BordergetTop()
Gets the top border.
BordergetVertical()
Gets the vertical border that is used between cells.
Borderget(int index)
Retrieves a Border object by index.
BordergetByBorderType(int borderType)
Retrieves a Border object by border type.
 
Method Summary
voidclearFormatting()
Removes all borders of an object.
booleanequals(BorderCollection brColl)
Compares collections of borders.
java.util.Iterator<Border>iterator()
Returns an enumerator object that can be used to iterate over all borders in the collection.
 

    • Property Getters/Setters Detail

      • getBottom

        public Border getBottom()
        
        Gets the bottom border.

        Example:

        Shows how to format table and cell with different borders and shadings
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        
        // Set the borders for the entire table.
        table.setBorders(LineStyle.SINGLE, 2.0, Color.BLACK);
        // Set the cell shading for this cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
        builder.writeln("Cell #1");
        
        builder.insertCell();
        // Specify a different cell shading for the second cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.writeln("Cell #2");
        
        // End this row.
        builder.endRow();
        
        // Clear the cell formatting from previous operations.
        builder.getCellFormat().clearFormatting();
        
        // Create the second row.
        builder.insertCell();
        
        // Create larger borders for the first cell of this row. This will be different
        // compared to the borders set for the table.
        builder.getCellFormat().getBorders().getLeft().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getRight().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getTop().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getBottom().setLineWidth(4.0);
        builder.writeln("Cell #3");
        
        builder.insertCell();
        // Clear the cell formatting from the previous cell.
        builder.getCellFormat().clearFormatting();
        builder.writeln("Cell #4");
        
        doc.save(getArtifactsDir() + "Table.SetBordersAndShading.doc");
      • getColor/setColor

        public java.awt.Color getColor() / public void setColor(java.awt.Color value)
        
        Gets or sets the border color.

        Returns the color of the first border in the collection.

        Sets the color of all borders in the collection excluding diagonal borders.

        Example:

        Creates a fancy looking green wavy page border with a shadow.
        Document doc = new Document();
        PageSetup ps = doc.getSections().get(0).getPageSetup();
        
        ps.getBorders().setLineStyle(LineStyle.DOUBLE_WAVE);
        ps.getBorders().setLineWidth(2);
        ps.getBorders().setColor(Color.GREEN);
        ps.getBorders().setDistanceFromText(24);
        ps.getBorders().setShadow(true);
        
        doc.save(getArtifactsDir() + "PageSetup.PageBorders.doc");
      • getCount

        public int getCount()
        
        Gets the number of borders in the collection.

        Example:

        Shows the equality of BorderCollections as well counting, visibility of their elements.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph 1."));
        
        Paragraph firstParagraph = doc.getFirstSection().getBody().getFirstParagraph();
        BorderCollection firstParaBorders = firstParagraph.getParagraphFormat().getBorders();
        
        builder.insertParagraph();
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph 2."));
        
        Paragraph secondParagraph = builder.getCurrentParagraph();
        BorderCollection secondParaBorders = secondParagraph.getParagraphFormat().getBorders();
        
        // Two paragraphs have two different BorderCollections, but share the elements that are in from the first paragraph
        for (int i = 0; i < firstParaBorders.getCount(); i++) {
            Assert.assertTrue(firstParaBorders.get(i).equals(secondParaBorders.get(i)));
            Assert.assertEquals(firstParaBorders.get(i).hashCode(), secondParaBorders.get(i).hashCode());
        
            // Borders are invisible by default
            Assert.assertFalse(firstParaBorders.get(i).isVisible());
        }
        
        // Each border in the second paragraph collection becomes no longer the same as its counterpart from the first paragraph collection
        // There are always 6 elements in a border collection, and changing all of them will make the second collection completely different from the first
        secondParaBorders.getByBorderType(BorderType.LEFT).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.RIGHT).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.TOP).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.BOTTOM).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.VERTICAL).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.HORIZONTAL).setLineStyle(LineStyle.DOT_DASH);
        
        // Now the BorderCollections both have their own elements
        for (int i = 0; i < firstParaBorders.getCount(); i++) {
            Assert.assertFalse(firstParaBorders.get(i).equals(secondParaBorders.get(i)));
            Assert.assertNotEquals(firstParaBorders.get(i).hashCode(), secondParaBorders.get(i).hashCode());
        
            // Changing the line style made the borders visible
            Assert.assertTrue(secondParaBorders.get(i).isVisible());
        }
      • getDistanceFromText/setDistanceFromText

        public double getDistanceFromText() / public void setDistanceFromText(double value)
        
        Gets or sets distance of the border from text in points.

        Gets the distance from text for the first border.

        Sets the distance from text for all borders in the collection excluding diagonal borders.

        Has no effect and will be automatically reset to zero for borders of table cells.

        Example:

        Creates a fancy looking green wavy page border with a shadow.
        Document doc = new Document();
        PageSetup ps = doc.getSections().get(0).getPageSetup();
        
        ps.getBorders().setLineStyle(LineStyle.DOUBLE_WAVE);
        ps.getBorders().setLineWidth(2);
        ps.getBorders().setColor(Color.GREEN);
        ps.getBorders().setDistanceFromText(24);
        ps.getBorders().setShadow(true);
        
        doc.save(getArtifactsDir() + "PageSetup.PageBorders.doc");
      • getHorizontal

        public Border getHorizontal()
        
        Gets the horizontal border that is used between cells or conforming paragraphs.

        Example:

        Shows the difference between the Horizontal and Vertical properties of BorderCollection.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A BorderCollection is one of a Paragraph's formatting properties
        Paragraph paragraph = doc.getFirstSection().getBody().getFirstParagraph();
        BorderCollection paragraphBorders = paragraph.getParagraphFormat().getBorders();
        
        // paragraphBorders belongs to the first paragraph, but these changes will apply to subsequently created paragraphs
        paragraphBorders.getHorizontal().setColor(Color.RED);
        paragraphBorders.getHorizontal().setLineStyle(LineStyle.DASH_SMALL_GAP);
        paragraphBorders.getHorizontal().setLineWidth(3.0);
        
        // Horizontal borders only appear under a paragraph if there's another paragraph under it
        // Right now the first paragraph has no borders
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph above horizontal border."));
        
        // Now the first paragraph will have a red dashed line border under it
        // This new second paragraph can have a border too, but only if we add another paragraph underneath it
        builder.insertParagraph();
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph below horizontal border."));
        
        // A table makes use of both vertical and horizontal properties of BorderCollection
        // Both these properties can only affect the inner borders of a table
        Table table = new Table(doc);
        doc.getFirstSection().getBody().appendChild(table);
        
        for (int i = 0; i < 3; i++) {
            Row row = new Row(doc);
            BorderCollection rowBorders = row.getRowFormat().getBorders();
        
            // Vertical borders are ones between rows in a table
            rowBorders.getHorizontal().setColor(Color.RED);
            rowBorders.getHorizontal().setLineStyle(LineStyle.DOT);
            rowBorders.getHorizontal().setLineWidth(2.0);
        
            // Vertical borders are ones between cells in a table
            rowBorders.getVertical().setColor(Color.BLUE);
            rowBorders.getVertical().setLineStyle(LineStyle.DOT);
            rowBorders.getVertical().setLineWidth(2.0);
        
            // A blue dotted vertical border will appear between cells
            // A red dotted border will appear between rows
            row.appendChild(new Cell(doc));
            row.getLastCell().appendChild(new Paragraph(doc));
            row.getLastCell().getFirstParagraph().appendChild(new Run(doc, "Vertical border to the right."));
        
            row.appendChild(new Cell(doc));
            row.getLastCell().appendChild(new Paragraph(doc));
            row.getLastCell().getFirstParagraph().appendChild(new Run(doc, "Vertical border to the left."));
            table.appendChild(row);
        }
        
        doc.save(getArtifactsDir() + "Border.HorizontalAndVerticalBorders.docx");
      • getLeft

        public Border getLeft()
        
        Gets the left border.

        Example:

        Shows how to format table and cell with different borders and shadings
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        
        // Set the borders for the entire table.
        table.setBorders(LineStyle.SINGLE, 2.0, Color.BLACK);
        // Set the cell shading for this cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
        builder.writeln("Cell #1");
        
        builder.insertCell();
        // Specify a different cell shading for the second cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.writeln("Cell #2");
        
        // End this row.
        builder.endRow();
        
        // Clear the cell formatting from previous operations.
        builder.getCellFormat().clearFormatting();
        
        // Create the second row.
        builder.insertCell();
        
        // Create larger borders for the first cell of this row. This will be different
        // compared to the borders set for the table.
        builder.getCellFormat().getBorders().getLeft().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getRight().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getTop().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getBottom().setLineWidth(4.0);
        builder.writeln("Cell #3");
        
        builder.insertCell();
        // Clear the cell formatting from the previous cell.
        builder.getCellFormat().clearFormatting();
        builder.writeln("Cell #4");
        
        doc.save(getArtifactsDir() + "Table.SetBordersAndShading.doc");
      • getLineStyle/setLineStyle

        public int getLineStyle() / public void setLineStyle(int value)
        
        Gets or sets the border style. The value of the property is LineStyle integer constant.

        Returns the style of the first border in the collection.

        Sets the style of all borders in the collection excluding diagonal borders.

        Example:

        Creates a fancy looking green wavy page border with a shadow.
        Document doc = new Document();
        PageSetup ps = doc.getSections().get(0).getPageSetup();
        
        ps.getBorders().setLineStyle(LineStyle.DOUBLE_WAVE);
        ps.getBorders().setLineWidth(2);
        ps.getBorders().setColor(Color.GREEN);
        ps.getBorders().setDistanceFromText(24);
        ps.getBorders().setShadow(true);
        
        doc.save(getArtifactsDir() + "PageSetup.PageBorders.doc");
      • getLineWidth/setLineWidth

        public double getLineWidth() / public void setLineWidth(double value)
        
        Gets or sets the border width in points.

        Returns the width of the first border in the collection.

        Sets the width of all borders in the collection excluding diagonal borders.

        Example:

        Creates a fancy looking green wavy page border with a shadow.
        Document doc = new Document();
        PageSetup ps = doc.getSections().get(0).getPageSetup();
        
        ps.getBorders().setLineStyle(LineStyle.DOUBLE_WAVE);
        ps.getBorders().setLineWidth(2);
        ps.getBorders().setColor(Color.GREEN);
        ps.getBorders().setDistanceFromText(24);
        ps.getBorders().setShadow(true);
        
        doc.save(getArtifactsDir() + "PageSetup.PageBorders.doc");
      • getRight

        public Border getRight()
        
        Gets the right border.

        Example:

        Shows how to format table and cell with different borders and shadings
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        
        // Set the borders for the entire table.
        table.setBorders(LineStyle.SINGLE, 2.0, Color.BLACK);
        // Set the cell shading for this cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
        builder.writeln("Cell #1");
        
        builder.insertCell();
        // Specify a different cell shading for the second cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.writeln("Cell #2");
        
        // End this row.
        builder.endRow();
        
        // Clear the cell formatting from previous operations.
        builder.getCellFormat().clearFormatting();
        
        // Create the second row.
        builder.insertCell();
        
        // Create larger borders for the first cell of this row. This will be different
        // compared to the borders set for the table.
        builder.getCellFormat().getBorders().getLeft().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getRight().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getTop().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getBottom().setLineWidth(4.0);
        builder.writeln("Cell #3");
        
        builder.insertCell();
        // Clear the cell formatting from the previous cell.
        builder.getCellFormat().clearFormatting();
        builder.writeln("Cell #4");
        
        doc.save(getArtifactsDir() + "Table.SetBordersAndShading.doc");
      • getShadow/setShadow

        public boolean getShadow() / public void setShadow(boolean value)
        
        Gets or sets a value indicating whether the border has a shadow.

        Gets the value from the first border in the collection.

        Sets the value for all borders in the collection excluding diagonal borders.

        Example:

        Creates a fancy looking green wavy page border with a shadow.
        Document doc = new Document();
        PageSetup ps = doc.getSections().get(0).getPageSetup();
        
        ps.getBorders().setLineStyle(LineStyle.DOUBLE_WAVE);
        ps.getBorders().setLineWidth(2);
        ps.getBorders().setColor(Color.GREEN);
        ps.getBorders().setDistanceFromText(24);
        ps.getBorders().setShadow(true);
        
        doc.save(getArtifactsDir() + "PageSetup.PageBorders.doc");
      • getTop

        public Border getTop()
        
        Gets the top border.

        Example:

        Shows how to format table and cell with different borders and shadings
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        Table table = builder.startTable();
        builder.insertCell();
        
        // Set the borders for the entire table.
        table.setBorders(LineStyle.SINGLE, 2.0, Color.BLACK);
        // Set the cell shading for this cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.RED);
        builder.writeln("Cell #1");
        
        builder.insertCell();
        // Specify a different cell shading for the second cell.
        builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
        builder.writeln("Cell #2");
        
        // End this row.
        builder.endRow();
        
        // Clear the cell formatting from previous operations.
        builder.getCellFormat().clearFormatting();
        
        // Create the second row.
        builder.insertCell();
        
        // Create larger borders for the first cell of this row. This will be different
        // compared to the borders set for the table.
        builder.getCellFormat().getBorders().getLeft().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getRight().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getTop().setLineWidth(4.0);
        builder.getCellFormat().getBorders().getBottom().setLineWidth(4.0);
        builder.writeln("Cell #3");
        
        builder.insertCell();
        // Clear the cell formatting from the previous cell.
        builder.getCellFormat().clearFormatting();
        builder.writeln("Cell #4");
        
        doc.save(getArtifactsDir() + "Table.SetBordersAndShading.doc");
      • getVertical

        public Border getVertical()
        
        Gets the vertical border that is used between cells.

        Example:

        Shows the difference between the Horizontal and Vertical properties of BorderCollection.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // A BorderCollection is one of a Paragraph's formatting properties
        Paragraph paragraph = doc.getFirstSection().getBody().getFirstParagraph();
        BorderCollection paragraphBorders = paragraph.getParagraphFormat().getBorders();
        
        // paragraphBorders belongs to the first paragraph, but these changes will apply to subsequently created paragraphs
        paragraphBorders.getHorizontal().setColor(Color.RED);
        paragraphBorders.getHorizontal().setLineStyle(LineStyle.DASH_SMALL_GAP);
        paragraphBorders.getHorizontal().setLineWidth(3.0);
        
        // Horizontal borders only appear under a paragraph if there's another paragraph under it
        // Right now the first paragraph has no borders
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph above horizontal border."));
        
        // Now the first paragraph will have a red dashed line border under it
        // This new second paragraph can have a border too, but only if we add another paragraph underneath it
        builder.insertParagraph();
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph below horizontal border."));
        
        // A table makes use of both vertical and horizontal properties of BorderCollection
        // Both these properties can only affect the inner borders of a table
        Table table = new Table(doc);
        doc.getFirstSection().getBody().appendChild(table);
        
        for (int i = 0; i < 3; i++) {
            Row row = new Row(doc);
            BorderCollection rowBorders = row.getRowFormat().getBorders();
        
            // Vertical borders are ones between rows in a table
            rowBorders.getHorizontal().setColor(Color.RED);
            rowBorders.getHorizontal().setLineStyle(LineStyle.DOT);
            rowBorders.getHorizontal().setLineWidth(2.0);
        
            // Vertical borders are ones between cells in a table
            rowBorders.getVertical().setColor(Color.BLUE);
            rowBorders.getVertical().setLineStyle(LineStyle.DOT);
            rowBorders.getVertical().setLineWidth(2.0);
        
            // A blue dotted vertical border will appear between cells
            // A red dotted border will appear between rows
            row.appendChild(new Cell(doc));
            row.getLastCell().appendChild(new Paragraph(doc));
            row.getLastCell().getFirstParagraph().appendChild(new Run(doc, "Vertical border to the right."));
        
            row.appendChild(new Cell(doc));
            row.getLastCell().appendChild(new Paragraph(doc));
            row.getLastCell().getFirstParagraph().appendChild(new Run(doc, "Vertical border to the left."));
            table.appendChild(row);
        }
        
        doc.save(getArtifactsDir() + "Border.HorizontalAndVerticalBorders.docx");
      • get

        public Border get(int index)
        
        Retrieves a Border object by index.
        Parameters:
        index - Zero-based index of the border to retrieve.

        Example:

        Shows the equality of BorderCollections as well counting, visibility of their elements.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph 1."));
        
        Paragraph firstParagraph = doc.getFirstSection().getBody().getFirstParagraph();
        BorderCollection firstParaBorders = firstParagraph.getParagraphFormat().getBorders();
        
        builder.insertParagraph();
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph 2."));
        
        Paragraph secondParagraph = builder.getCurrentParagraph();
        BorderCollection secondParaBorders = secondParagraph.getParagraphFormat().getBorders();
        
        // Two paragraphs have two different BorderCollections, but share the elements that are in from the first paragraph
        for (int i = 0; i < firstParaBorders.getCount(); i++) {
            Assert.assertTrue(firstParaBorders.get(i).equals(secondParaBorders.get(i)));
            Assert.assertEquals(firstParaBorders.get(i).hashCode(), secondParaBorders.get(i).hashCode());
        
            // Borders are invisible by default
            Assert.assertFalse(firstParaBorders.get(i).isVisible());
        }
        
        // Each border in the second paragraph collection becomes no longer the same as its counterpart from the first paragraph collection
        // There are always 6 elements in a border collection, and changing all of them will make the second collection completely different from the first
        secondParaBorders.getByBorderType(BorderType.LEFT).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.RIGHT).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.TOP).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.BOTTOM).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.VERTICAL).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.HORIZONTAL).setLineStyle(LineStyle.DOT_DASH);
        
        // Now the BorderCollections both have their own elements
        for (int i = 0; i < firstParaBorders.getCount(); i++) {
            Assert.assertFalse(firstParaBorders.get(i).equals(secondParaBorders.get(i)));
            Assert.assertNotEquals(firstParaBorders.get(i).hashCode(), secondParaBorders.get(i).hashCode());
        
            // Changing the line style made the borders visible
            Assert.assertTrue(secondParaBorders.get(i).isVisible());
        }
      • getByBorderType

        public Border getByBorderType(int borderType)
        
        Retrieves a Border object by border type.

        Note that not all borders are present for different document elements. This method throws an exception if you request a border not applicable to the current object.

        Parameters:
        borderType - A BorderType value. A BorderType value that specifies the type of the border to retrieve.

        Example:

        Shows how to apply borders and shading to a paragraph.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set paragraph borders
        BorderCollection borders = builder.getParagraphFormat().getBorders();
        borders.setDistanceFromText(20);
        borders.getByBorderType(BorderType.LEFT).setLineStyle(LineStyle.DOUBLE);
        borders.getByBorderType(BorderType.RIGHT).setLineStyle(LineStyle.DOUBLE);
        borders.getByBorderType(BorderType.TOP).setLineStyle(LineStyle.DOUBLE);
        borders.getByBorderType(BorderType.BOTTOM).setLineStyle(LineStyle.DOUBLE);
        
        // Set paragraph shading
        Shading shading = builder.getParagraphFormat().getShading();
        shading.setTexture(TextureIndex.TEXTURE_DIAGONAL_CROSS);
        shading.setBackgroundPatternColor(new Color(240, 128, 128));  // Light Coral
        shading.setForegroundPatternColor(new Color(255, 160, 122));  // Light Salmon
        
        builder.write("I'm a formatted paragraph with double border and nice shading.");
    • Method Detail

      • clearFormatting

        public void clearFormatting()
        Removes all borders of an object.

        Example:

        Shows how to remove all borders from a paragraph at once.
        Document doc = new Document(getMyDir() + "Border.Borders.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        BorderCollection borders = builder.getParagraphFormat().getBorders();
        
        borders.clearFormatting();
      • equals

        public boolean equals(BorderCollection brColl)
                      throws java.lang.Exception
        Compares collections of borders.

        Example:

        Shows the equality of BorderCollections as well counting, visibility of their elements.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph 1."));
        
        Paragraph firstParagraph = doc.getFirstSection().getBody().getFirstParagraph();
        BorderCollection firstParaBorders = firstParagraph.getParagraphFormat().getBorders();
        
        builder.insertParagraph();
        builder.getCurrentParagraph().appendChild(new Run(doc, "Paragraph 2."));
        
        Paragraph secondParagraph = builder.getCurrentParagraph();
        BorderCollection secondParaBorders = secondParagraph.getParagraphFormat().getBorders();
        
        // Two paragraphs have two different BorderCollections, but share the elements that are in from the first paragraph
        for (int i = 0; i < firstParaBorders.getCount(); i++) {
            Assert.assertTrue(firstParaBorders.get(i).equals(secondParaBorders.get(i)));
            Assert.assertEquals(firstParaBorders.get(i).hashCode(), secondParaBorders.get(i).hashCode());
        
            // Borders are invisible by default
            Assert.assertFalse(firstParaBorders.get(i).isVisible());
        }
        
        // Each border in the second paragraph collection becomes no longer the same as its counterpart from the first paragraph collection
        // There are always 6 elements in a border collection, and changing all of them will make the second collection completely different from the first
        secondParaBorders.getByBorderType(BorderType.LEFT).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.RIGHT).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.TOP).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.BOTTOM).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.VERTICAL).setLineStyle(LineStyle.DOT_DASH);
        secondParaBorders.getByBorderType(BorderType.HORIZONTAL).setLineStyle(LineStyle.DOT_DASH);
        
        // Now the BorderCollections both have their own elements
        for (int i = 0; i < firstParaBorders.getCount(); i++) {
            Assert.assertFalse(firstParaBorders.get(i).equals(secondParaBorders.get(i)));
            Assert.assertNotEquals(firstParaBorders.get(i).hashCode(), secondParaBorders.get(i).hashCode());
        
            // Changing the line style made the borders visible
            Assert.assertTrue(secondParaBorders.get(i).isVisible());
        }
      • iterator

        public java.util.Iterator<Border> iterator()
        Returns an enumerator object that can be used to iterate over all borders in the collection.

        Example:

        Shows how to enumerate all borders in a collection.
        Document doc = new Document(getMyDir() + "Border.Borders.doc");
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        BorderCollection borders = builder.getParagraphFormat().getBorders();
        
        Iterator<Border> enumerator = borders.iterator();
        while (enumerator.hasNext()) {
            // Do something useful.
            Border b = enumerator.next();
            b.setColor(new Color(65, 105, 225));//RoyalBlue
            b.setLineStyle(LineStyle.DOUBLE);
        }
        
        doc.save(getArtifactsDir() + "Border.ChangedColourBorder.doc");