Ta EnumLines

// Create a text area
JTextArea textArea = new JTextArea("word1 word2nword3nword4");

// Get paragraph element
Element paragraph = textArea.getDocument().getDefaultRootElement();

// Get number of content elements
int contentCount = paragraph.getElementCount();

// Get index ranges for each content element.
// Each content element represents one line.
// Each line includes the terminating newline.
for (int i=0; i<contentCount; i++) {
    Element e = paragraph.getElement(i);
    int rangeStart = e.getStartOffset();
    int rangeEnd = e.getEndOffset();
    try {
        String line = textArea.getText(rangeStart, rangeEnd-rangeStart);
    } catch (BadLocationException ex) {

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.