Code example for JTextComponent

Methods: getCaretPositiongetDocument

0
     * @param txtCmp Text Component 
     * @return Line number 
     */ 
    public static int getCaretLine(JTextComponent txtCmp)
    { 
        return getLine(txtCmp.getDocument(), txtCmp.getCaretPosition());
    } 
 
    /** 
     * Given an offset, returns the line number of a text component. 
     *  
     * @param txtCmp Text Component 
     * @param offset Offset position 
     * @return Line number starting in 0. 
     */ 
    public static int getLine(JTextComponent txtCmp, int offset)
    { 
        return getLine(txtCmp.getDocument(), offset);
    }