public class CommentCollection extends NodeCollection
Comment nodes.
To learn more, visit the Working with Comments documentation article.
Examples:
Shows how to mark a comment as "done".
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Helo world!");
// Insert a comment to point out an error.
Comment comment = new Comment(doc, "John Doe", "J.D.", new Date());
comment.setText("Fix the spelling error!");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(comment);
// Comments have a "Done" flag, which is set to "false" by default.
// If a comment suggests that we make a change within the document,
// we can apply the change, and then also set the "Done" flag afterwards to indicate the correction.
Assert.assertFalse(comment.getDone());
doc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0).setText("Hello world!");
comment.setDone(true);
// Comments that are "done" will differentiate themselves
// from ones that are not "done" with a faded text color.
comment = new Comment(doc, "John Doe", "J.D.", new Date());
comment.setText("Add text to this paragraph.");
builder.getCurrentParagraph().appendChild(comment);
doc.save(getArtifactsDir() + "Comment.Done.docx");
| Modifier and Type | Method and Description |
|---|---|
Comment |
get(int index)
Retrieves a
Comment at the given index. |
add, clear, contains, getContainer, getCount, getCurrentNode, getNextMatchingNode, indexOf, insert, iterator, remove, removeAt, toArraypublic Comment get(int index)
Comment at the given index.
Remarks:
The index is zero-based.
Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.
If index is greater than or equal to the number of items in the list, this returns a null reference.
If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.
Examples:
Shows how to remove comment replies.
Document doc = new Document();
Comment comment = new Comment(doc, "John Doe", "J.D.", new Date());
comment.setText("My comment.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(comment);
comment.addReply("Joe Bloggs", "J.B.", new Date(), "New reply");
comment.addReply("Joe Bloggs", "J.B.", new Date(), "Another reply");
Assert.assertEquals(2, comment.getReplies().getCount());
// Below are two ways of removing replies from a comment.
// 1 - Use the "RemoveReply" method to remove replies from a comment individually:
comment.removeReply(comment.getReplies().get(0));
Assert.assertEquals(1, comment.getReplies().getCount());
// 2 - Use the "RemoveAllReplies" method to remove all replies from a comment at once:
comment.removeAllReplies();
Assert.assertEquals(0, comment.getReplies().getCount());
get in class NodeCollectionindex - An index into the collection.Comment value.