Here you can find the source of getElementForLine(Document document, int line)
public static Element getElementForLine(Document document, int line)
//package com.java2s; import javax.swing.text.Document; import javax.swing.text.Element; public class Main { public static Element getElementForLine(Document document, int line) { Element[] roots = document.getRootElements(); Element root = roots[0];/*from ww w .j a v a2s .com*/ return root.getElement(line - 1); } }