com.aspose.words

Class ListLevel

  • java.lang.Object
    • com.aspose.words.ListLevel
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class ListLevel 
    extends java.lang.Object

Defines formatting for a list level.

You do not create objects of this class. List level objects are created automatically when a list is created. You access ListLevel objects via the ListLevelCollection collection.

Use the properties of ListLevel to specify list formatting for individual list levels.

Example:

Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
Document doc = new Document();

// Create a list based on one of the Microsoft Word list templates
List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);

// Completely customize one list level
ListLevel listLevel = list.getListLevels().get(0);
listLevel.getFont().setColor(Color.RED);
listLevel.getFont().setSize(24.0);
listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
listLevel.setStartAt(21);
listLevel.setNumberFormat("\u0000");

listLevel.setNumberPosition(-36);
listLevel.setTextPosition(144.0);
listLevel.setTabPosition(144.0);

// Customize another list level
listLevel = list.getListLevels().get(1);
listLevel.setAlignment(ListLevelAlignment.RIGHT);
listLevel.setNumberStyle(NumberStyle.BULLET);
listLevel.getFont().setName("Wingdings");
listLevel.getFont().setColor(Color.BLUE);
listLevel.getFont().setSize(24.0);
listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
listLevel.setNumberPosition(144.0);

// Now add some text that uses the list that we created
// It does not matter when to customize the list - before or after adding the paragraphs
DocumentBuilder builder = new DocumentBuilder(doc);

builder.getListFormat().setList(list);
builder.writeln("The quick brown fox...");
builder.writeln("The quick brown fox...");

builder.getListFormat().listIndent();
builder.writeln("jumped over the lazy dog.");
builder.writeln("jumped over the lazy dog.");

builder.getListFormat().listOutdent();
builder.writeln("The quick brown fox...");

builder.getListFormat().removeNumbers();

builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");

Property Getters/Setters Summary
intgetAlignment()
void
setAlignment(intvalue)
           Gets or sets the justification of the actual number of the list item. The value of the property is ListLevelAlignment integer constant.
FontgetFont()
Specifies character formatting used for the list label.
ImageDatagetImageData()
Returns image data of the picture bullet shape for the current list level.
booleanisLegal()
void
isLegal(booleanvalue)
           True if the level turns all inherited numbers to Arabic, false if it preserves their number style.
StylegetLinkedStyle()
void
           Gets or sets the paragraph style that is linked to this list level.
java.lang.StringgetNumberFormat()
void
setNumberFormat(java.lang.Stringvalue)
           Returns or sets the number format for the list level.
doublegetNumberPosition()
void
setNumberPosition(doublevalue)
           Returns or sets the position (in points) of the number or bullet for the list level.
intgetNumberStyle()
void
setNumberStyle(intvalue)
           Returns or sets the number style for this list level. The value of the property is NumberStyle integer constant.
intgetRestartAfterLevel()
void
           Sets or returns the list level that must appear before the specified list level restarts numbering.
intgetStartAt()
void
setStartAt(intvalue)
           Returns or sets the starting number for this list level.
doublegetTabPosition()
void
setTabPosition(doublevalue)
           Returns or sets the tab position (in points) for the list level.
doublegetTextPosition()
void
setTextPosition(doublevalue)
           Returns or sets the position (in points) for the second line of wrapping text for the list level.
intgetTrailingCharacter()
void
           Returns or sets the character inserted after the number for the list level. The value of the property is ListTrailingCharacter integer constant.
 
Method Summary
voidcreatePictureBullet()
Creates picture bullet shape for the current list level.
voiddeletePictureBullet()
Deletes picture bullet for the current list level.
booleanequals(ListLevel level)
Compares with the specified ListLevel.
inthashCode()
Calculates hash code for this object.
 

    • Property Getters/Setters Detail

      • getAlignment/setAlignment

        public int getAlignment() / public void setAlignment(int value)
        
        Gets or sets the justification of the actual number of the list item. The value of the property is ListLevelAlignment integer constant.

        The list label is justified relative to the NumberPosition property.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
      • getFont

        public Font getFont()
        
        Specifies character formatting used for the list label.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
      • getImageData

        public ImageData getImageData()
        
        Returns image data of the picture bullet shape for the current list level. If this level doesn't define picture bullet returns null. Before setting new image for non picture bullet shape, please use createPictureBullet() method first.
      • isLegal/isLegal

        public boolean isLegal() / public void isLegal(boolean value)
        
        True if the level turns all inherited numbers to Arabic, false if it preserves their number style.

        Example:

        Shows how to create a list with some advanced formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Level 1 labels will be "Appendix A", continuous and linked to the Heading 1 paragraph style
        list.getListLevels().get(0).setNumberFormat("Appendix \u0000");
        list.getListLevels().get(0).setNumberStyle(NumberStyle.UPPERCASE_LETTER);
        list.getListLevels().get(0).setLinkedStyle(doc.getStyles().get("Heading 1"));
        
        // Level 2 labels will be "Section (1.01)" and restarting after Level 2 item appears
        list.getListLevels().get(1).setNumberFormat("Section (\u0000.\u0001)");
        list.getListLevels().get(1).setNumberStyle(NumberStyle.LEADING_ZERO);
        // Notice the higher level uses UppercaseLetter numbering, but we want arabic number
        // of the higher levels to appear in this level, therefore set this property
        list.getListLevels().get(1).isLegal(true);
        list.getListLevels().get(1).setRestartAfterLevel(0);
        
        // Level 3 labels will be "-I-" and restarting after Level 2 item appears
        list.getListLevels().get(2).setNumberFormat("-\u0002-");
        list.getListLevels().get(2).setNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        list.getListLevels().get(2).setRestartAfterLevel(1);
        
        // Make labels of all list levels bold
        for (ListLevel level : list.getListLevels())
            level.getFont().setBold(true);
        
        // Apply list formatting to the current paragraph
        builder.getListFormat().setList(list);
        
        // Exercise the 3 levels we created two times
        for (int n = 0; n < 2; n++) {
            for (int i = 0; i < 3; i++) {
                builder.getListFormat().setListLevelNumber(i);
                builder.writeln("Level " + i);
            }
        }
        
        builder.getListFormat().removeNumbers();
        
        doc.save(getArtifactsDir() + "Lists.CreateListRestartAfterHigher.docx");
      • getLinkedStyle/setLinkedStyle

        public Style getLinkedStyle() / public void setLinkedStyle(Style value)
        
        Gets or sets the paragraph style that is linked to this list level.

        This property is null when the list level is not linked to a paragraph style. This property can be set to null.

        Example:

        Shows how to create a list with some advanced formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Level 1 labels will be "Appendix A", continuous and linked to the Heading 1 paragraph style
        list.getListLevels().get(0).setNumberFormat("Appendix \u0000");
        list.getListLevels().get(0).setNumberStyle(NumberStyle.UPPERCASE_LETTER);
        list.getListLevels().get(0).setLinkedStyle(doc.getStyles().get("Heading 1"));
        
        // Level 2 labels will be "Section (1.01)" and restarting after Level 2 item appears
        list.getListLevels().get(1).setNumberFormat("Section (\u0000.\u0001)");
        list.getListLevels().get(1).setNumberStyle(NumberStyle.LEADING_ZERO);
        // Notice the higher level uses UppercaseLetter numbering, but we want arabic number
        // of the higher levels to appear in this level, therefore set this property
        list.getListLevels().get(1).isLegal(true);
        list.getListLevels().get(1).setRestartAfterLevel(0);
        
        // Level 3 labels will be "-I-" and restarting after Level 2 item appears
        list.getListLevels().get(2).setNumberFormat("-\u0002-");
        list.getListLevels().get(2).setNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        list.getListLevels().get(2).setRestartAfterLevel(1);
        
        // Make labels of all list levels bold
        for (ListLevel level : list.getListLevels())
            level.getFont().setBold(true);
        
        // Apply list formatting to the current paragraph
        builder.getListFormat().setList(list);
        
        // Exercise the 3 levels we created two times
        for (int n = 0; n < 2; n++) {
            for (int i = 0; i < 3; i++) {
                builder.getListFormat().setListLevelNumber(i);
                builder.writeln("Level " + i);
            }
        }
        
        builder.getListFormat().removeNumbers();
        
        doc.save(getArtifactsDir() + "Lists.CreateListRestartAfterHigher.docx");
      • getNumberFormat/setNumberFormat

        public java.lang.String getNumberFormat() / public void setNumberFormat(java.lang.String value)
        
        Returns or sets the number format for the list level.

        Among normal text characters, the string can contain placeholder characters \x0000 to \x0008 representing the numbers from the corresponding list levels.

        For example, the string "\x0000.\x0001)" will generate a list label that looks something like "1.5)". The number "1" is the current number from the 1st list level, the number "5" is the current number from the 2nd list level.

        Null is not allowed, but an empty string meaning no number is valid.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");

        Example:

        Shows how to create a list with some advanced formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Level 1 labels will be "Appendix A", continuous and linked to the Heading 1 paragraph style
        list.getListLevels().get(0).setNumberFormat("Appendix \u0000");
        list.getListLevels().get(0).setNumberStyle(NumberStyle.UPPERCASE_LETTER);
        list.getListLevels().get(0).setLinkedStyle(doc.getStyles().get("Heading 1"));
        
        // Level 2 labels will be "Section (1.01)" and restarting after Level 2 item appears
        list.getListLevels().get(1).setNumberFormat("Section (\u0000.\u0001)");
        list.getListLevels().get(1).setNumberStyle(NumberStyle.LEADING_ZERO);
        // Notice the higher level uses UppercaseLetter numbering, but we want arabic number
        // of the higher levels to appear in this level, therefore set this property
        list.getListLevels().get(1).isLegal(true);
        list.getListLevels().get(1).setRestartAfterLevel(0);
        
        // Level 3 labels will be "-I-" and restarting after Level 2 item appears
        list.getListLevels().get(2).setNumberFormat("-\u0002-");
        list.getListLevels().get(2).setNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        list.getListLevels().get(2).setRestartAfterLevel(1);
        
        // Make labels of all list levels bold
        for (ListLevel level : list.getListLevels())
            level.getFont().setBold(true);
        
        // Apply list formatting to the current paragraph
        builder.getListFormat().setList(list);
        
        // Exercise the 3 levels we created two times
        for (int n = 0; n < 2; n++) {
            for (int i = 0; i < 3; i++) {
                builder.getListFormat().setListLevelNumber(i);
                builder.writeln("Level " + i);
            }
        }
        
        builder.getListFormat().removeNumbers();
        
        doc.save(getArtifactsDir() + "Lists.CreateListRestartAfterHigher.docx");
      • getNumberPosition/setNumberPosition

        public double getNumberPosition() / public void setNumberPosition(double value)
        
        Returns or sets the position (in points) of the number or bullet for the list level.

        NumberPosition corresponds to LeftIndent plus FirstLineIndent of the paragraph.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
        See Also:
        TextPosition, TabPosition
      • getNumberStyle/setNumberStyle

        public int getNumberStyle() / public void setNumberStyle(int value)
        
        Returns or sets the number style for this list level. The value of the property is NumberStyle integer constant.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");

        Example:

        Shows how to create a list with some advanced formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Level 1 labels will be "Appendix A", continuous and linked to the Heading 1 paragraph style
        list.getListLevels().get(0).setNumberFormat("Appendix \u0000");
        list.getListLevels().get(0).setNumberStyle(NumberStyle.UPPERCASE_LETTER);
        list.getListLevels().get(0).setLinkedStyle(doc.getStyles().get("Heading 1"));
        
        // Level 2 labels will be "Section (1.01)" and restarting after Level 2 item appears
        list.getListLevels().get(1).setNumberFormat("Section (\u0000.\u0001)");
        list.getListLevels().get(1).setNumberStyle(NumberStyle.LEADING_ZERO);
        // Notice the higher level uses UppercaseLetter numbering, but we want arabic number
        // of the higher levels to appear in this level, therefore set this property
        list.getListLevels().get(1).isLegal(true);
        list.getListLevels().get(1).setRestartAfterLevel(0);
        
        // Level 3 labels will be "-I-" and restarting after Level 2 item appears
        list.getListLevels().get(2).setNumberFormat("-\u0002-");
        list.getListLevels().get(2).setNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        list.getListLevels().get(2).setRestartAfterLevel(1);
        
        // Make labels of all list levels bold
        for (ListLevel level : list.getListLevels())
            level.getFont().setBold(true);
        
        // Apply list formatting to the current paragraph
        builder.getListFormat().setList(list);
        
        // Exercise the 3 levels we created two times
        for (int n = 0; n < 2; n++) {
            for (int i = 0; i < 3; i++) {
                builder.getListFormat().setListLevelNumber(i);
                builder.writeln("Level " + i);
            }
        }
        
        builder.getListFormat().removeNumbers();
        
        doc.save(getArtifactsDir() + "Lists.CreateListRestartAfterHigher.docx");
      • getRestartAfterLevel/setRestartAfterLevel

        public int getRestartAfterLevel() / public void setRestartAfterLevel(int value)
        
        Sets or returns the list level that must appear before the specified list level restarts numbering.

        The value of -1 means the numbering will continue.

        Example:

        Shows how to create a list with some advanced formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Level 1 labels will be "Appendix A", continuous and linked to the Heading 1 paragraph style
        list.getListLevels().get(0).setNumberFormat("Appendix \u0000");
        list.getListLevels().get(0).setNumberStyle(NumberStyle.UPPERCASE_LETTER);
        list.getListLevels().get(0).setLinkedStyle(doc.getStyles().get("Heading 1"));
        
        // Level 2 labels will be "Section (1.01)" and restarting after Level 2 item appears
        list.getListLevels().get(1).setNumberFormat("Section (\u0000.\u0001)");
        list.getListLevels().get(1).setNumberStyle(NumberStyle.LEADING_ZERO);
        // Notice the higher level uses UppercaseLetter numbering, but we want arabic number
        // of the higher levels to appear in this level, therefore set this property
        list.getListLevels().get(1).isLegal(true);
        list.getListLevels().get(1).setRestartAfterLevel(0);
        
        // Level 3 labels will be "-I-" and restarting after Level 2 item appears
        list.getListLevels().get(2).setNumberFormat("-\u0002-");
        list.getListLevels().get(2).setNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        list.getListLevels().get(2).setRestartAfterLevel(1);
        
        // Make labels of all list levels bold
        for (ListLevel level : list.getListLevels())
            level.getFont().setBold(true);
        
        // Apply list formatting to the current paragraph
        builder.getListFormat().setList(list);
        
        // Exercise the 3 levels we created two times
        for (int n = 0; n < 2; n++) {
            for (int i = 0; i < 3; i++) {
                builder.getListFormat().setListLevelNumber(i);
                builder.writeln("Level " + i);
            }
        }
        
        builder.getListFormat().removeNumbers();
        
        doc.save(getArtifactsDir() + "Lists.CreateListRestartAfterHigher.docx");
      • getStartAt/setStartAt

        public int getStartAt() / public void setStartAt(int value)
        
        Returns or sets the starting number for this list level.

        Default value is 1.

        Example:

        Shows how to restart numbering in a list by copying a list.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a list based on a template
        List list1 = doc.getLists().add(ListTemplate.NUMBER_ARABIC_PARENTHESIS);
        // Modify the formatting of the list
        list1.getListLevels().get(0).getFont().setColor(Color.RED);
        list1.getListLevels().get(0).setAlignment(ListLevelAlignment.RIGHT);
        
        builder.writeln("List 1 starts below:");
        // Use the first list in the document for a while
        builder.getListFormat().setList(list1);
        builder.writeln("Item 1");
        builder.writeln("Item 2");
        builder.getListFormat().removeNumbers();
        
        // Now I want to reuse the first list, but need to restart numbering
        // This should be done by creating a copy of the original list formatting
        List list2 = doc.getLists().addCopy(list1);
        
        // We can modify the new list in any way. Including setting new start number
        list2.getListLevels().get(0).setStartAt(10);
        
        // Use the second list in the document
        builder.writeln("List 2 starts below:");
        builder.getListFormat().setList(list2);
        builder.writeln("Item 1");
        builder.writeln("Item 2");
        builder.getListFormat().removeNumbers();
        
        doc.save(getArtifactsDir() + "Lists.RestartNumberingUsingListCopy.docx");

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
      • getTabPosition/setTabPosition

        public double getTabPosition() / public void setTabPosition(double value)
        
        Returns or sets the tab position (in points) for the list level.

        Has effect only when TrailingCharacter is a tab.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
        See Also:
        NumberPosition, TextPosition
      • getTextPosition/setTextPosition

        public double getTextPosition() / public void setTextPosition(double value)
        
        Returns or sets the position (in points) for the second line of wrapping text for the list level.

        TextPosition corresponds to LeftIndent of the paragraph.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
        See Also:
        NumberPosition, TabPosition
      • getTrailingCharacter/setTrailingCharacter

        public int getTrailingCharacter() / public void setTrailingCharacter(int value)
        
        Returns or sets the character inserted after the number for the list level. The value of the property is ListTrailingCharacter integer constant.

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level
        ListLevel listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // Now add some text that uses the list that we created
        // It does not matter when to customize the list - before or after adding the paragraphs
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
    • Method Detail

      • createPictureBullet

        public void createPictureBullet()
                                throws java.lang.Exception
        Creates picture bullet shape for the current list level. Please note, NumberStyle will be set to Bullet and NumberFormat to "\xF0B7" to properly display picture bullet. Red cross image will be set as picture bullet image upon creating. To change it please use ImageData.

        Example:

        Shows how to creating and deleting picture bullet with custom image.
        Document doc = new Document();
        
        // Create a list with template
        List list = doc.getLists().add(ListTemplate.BULLET_CIRCLE);
        
        // Create picture bullet for the current list level
        list.getListLevels().get(0).createPictureBullet();
        
        // Set your own picture bullet image through the ImageData
        list.getListLevels().get(0).getImageData().setImage(getImageDir() + "Logo icon.ico");
        
        Assert.assertTrue(list.getListLevels().get(0).getImageData().hasImage());
        
        // Create a list, configure its bullets to use our image and add two list items
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("Hello world!");
        builder.write("Hello again!");
        
        doc.save(getArtifactsDir() + "Lists.CreatePictureBullet.docx");
        
        // Delete picture bullet
        list.getListLevels().get(0).deletePictureBullet();
        
        Assert.assertNull(list.getListLevels().get(0).getImageData());
      • deletePictureBullet

        public void deletePictureBullet()
        Deletes picture bullet for the current list level. Default bullet will be shown after deleting.

        Example:

        Shows how to creating and deleting picture bullet with custom image.
        Document doc = new Document();
        
        // Create a list with template
        List list = doc.getLists().add(ListTemplate.BULLET_CIRCLE);
        
        // Create picture bullet for the current list level
        list.getListLevels().get(0).createPictureBullet();
        
        // Set your own picture bullet image through the ImageData
        list.getListLevels().get(0).getImageData().setImage(getImageDir() + "Logo icon.ico");
        
        Assert.assertTrue(list.getListLevels().get(0).getImageData().hasImage());
        
        // Create a list, configure its bullets to use our image and add two list items
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("Hello world!");
        builder.write("Hello again!");
        
        doc.save(getArtifactsDir() + "Lists.CreatePictureBullet.docx");
        
        // Delete picture bullet
        list.getListLevels().get(0).deletePictureBullet();
        
        Assert.assertNull(list.getListLevels().get(0).getImageData());
      • equals

        public boolean equals(ListLevel level)
        Compares with the specified ListLevel.
      • hashCode

        public int hashCode()
        Calculates hash code for this object.