Here you can find the source of currentLineChanged(final JTextComponent c)
Parameter | Description |
---|---|
c | the text component |
private static void currentLineChanged(final JTextComponent c)
//package com.java2s; /* This file is part of the project "Hilbert II" - http://www.qedeq.org * * The main author is Santhosh Kumar T. Visit his great home page under: * http://www.jroller.com/santhosh//*from ww w . j a v a2 s .c o m*/ * * The original source for this file is: * http://www.jroller.com/santhosh/entry/currentlinehighlighter_contd * * It is distributed under the GNU Lesser General Public License: * http://www.gnu.org/copyleft/lesser.html */ import java.awt.Rectangle; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; public class Main { /** NOI18N - used as client property. */ private static final String PREVIOUS_CARET = "previousCaret"; /** * Fetches the previous caret location, stores the current caret location. If the caret is on * another line, repaint the previous line and the current line * * @param c the text component */ private static void currentLineChanged(final JTextComponent c) { if (null == c.getClientProperty(PREVIOUS_CARET)) { return; } try { final int previousCaret = ((Integer) c.getClientProperty(PREVIOUS_CARET)).intValue(); final Rectangle prev = c.modelToView(previousCaret); final Rectangle r = c.modelToView(c.getCaretPosition()); c.putClientProperty(PREVIOUS_CARET, new Integer(c.getCaretPosition())); if (prev.y != r.y) { c.repaint(0, prev.y, c.getWidth(), r.height); c.repaint(0, r.y, c.getWidth(), r.height); } } catch (final BadLocationException ignore) { // ignore } } }