Code example for JTextComponent

Methods: getFontgetFontMetricsgetY

0
     * @param txtCmp Text component. 
     * @return The line. 
     */ 
    public static int getTopLine(JTextComponent txtCmp)
    { 
        FontMetrics fm = txtCmp.getFontMetrics(txtCmp.getFont());
        int fontHeight = fm.getHeight();
 
        return (Math.abs(txtCmp.getY()) + fm.getAscent()) / fontHeight + 1;
    } 
 
    /** 
     * Get last visible line of the text component in a JScrollPane. 
     *  
     * @param txtCmp Text component. 
     * @return The line. 
     */ 
    public static int getBottomLine(JTextComponent txtCmp)
    { 
        FontMetrics fm = txtCmp.getFontMetrics(txtCmp.getFont());