List of usage examples for javax.swing JTextArea getText
public String getText(int offs, int len) throws BadLocationException
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextArea textArea = new JTextArea("word1 word2\nword3\nword4"); Element paragraph = textArea.getDocument().getDefaultRootElement(); int contentCount = paragraph.getElementCount(); for (int i = 0; i < contentCount; i++) { Element e = paragraph.getElement(i); int rangeStart = e.getStartOffset(); int rangeEnd = e.getEndOffset(); String line = textArea.getText(rangeStart, rangeEnd - rangeStart); System.out.println(line); }// w w w . j a v a2 s .c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextArea textArea = new JTextArea("word1 word2\nword3\nword4"); Document doc = textArea.getDocument(); ElementIterator it = new ElementIterator(doc.getDefaultRootElement()); Element e;//www . j a va2s . c om while ((e = it.next()) != null) { if (e.isLeaf()) { int rangeStart = e.getStartOffset(); int rangeEnd = e.getEndOffset(); String line = textArea.getText(rangeStart, rangeEnd - rangeStart); System.out.println(line); } } }