Enumerating the Paragraphs of a JTextPane Component
import javax.swing.JTextPane;
import javax.swing.text.Element;
publicclass Main {
publicstaticvoid main(String[] argv) throws Exception {
JTextPane textPane = new JTextPane();
Element section = textPane.getDocument().getDefaultRootElement();
int paraCount = section.getElementCount();
for (int i = 0; i < paraCount; i++) {
Element e = section.getElement(i);
int rangeStart = e.getStartOffset();
int rangeEnd = e.getEndOffset();
String para = textPane.getText(rangeStart, rangeEnd - rangeStart);
System.out.println(para);
}
}
}