/** * Overridden to (possibly) draw the caret's position. * * @param g The graphics context. */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (caretLineY>-1) { g.setColor(getCaretMarkerColor()); g.fillRect(0, caretLineY, getWidth(), 2); } }
/** * Toggles whether the caret's current location should be drawn. * * @param follow Whether the caret's current location should be followed. * @see #getFollowCaret() */ public void setFollowCaret(boolean follow) { if (followCaret!=follow) { if (followCaret) { repaint(0,caretLineY, getWidth(),2); // Erase } caretLineY = -1; lastLineY = -1; followCaret = follow; listener.caretUpdate(null); // Possibly repaint } }
@Override public void caretUpdate(CaretEvent e) { if (getFollowCaret()) { int line = textArea.getCaretLineNumber(); float percent = line / (float)(textArea.getLineCount()-1); textArea.computeVisibleRect(visibleRect); caretLineY = (int)(visibleRect.height*percent); if (caretLineY!=lastLineY) { repaint(0,lastLineY, getWidth(), 2); // Erase old position repaint(0,caretLineY, getWidth(), 2); lastLineY = caretLineY; } } }
/** * Overridden to (possibly) draw the caret's position. * * @param g The graphics context. */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (caretLineY>-1) { g.setColor(getCaretMarkerColor()); g.fillRect(0, caretLineY, getWidth(), 2); } }
/** * Overridden to (possibly) draw the caret's position. * * @param g The graphics context. */ protected void paintComponent(Graphics g) { super.paintComponent(g); if (caretLineY>-1) { g.setColor(getCaretMarkerColor()); g.fillRect(0, caretLineY, getWidth(), 2); } }
/** * Toggles whether the caret's current location should be drawn. * * @param follow Whether the caret's current location should be followed. * @see #getFollowCaret() */ public void setFollowCaret(boolean follow) { if (followCaret!=follow) { if (followCaret) { repaint(0,caretLineY, getWidth(),2); // Erase } caretLineY = -1; lastLineY = -1; followCaret = follow; listener.caretUpdate(null); // Possibly repaint } }
/** * Toggles whether the caret's current location should be drawn. * * @param follow Whether the caret's current location should be followed. * @see #getFollowCaret() */ public void setFollowCaret(boolean follow) { if (followCaret!=follow) { if (followCaret) { repaint(0,caretLineY, getWidth(),2); // Erase } caretLineY = -1; lastLineY = -1; followCaret = follow; listener.caretUpdate(null); // Possibly repaint } }
public void caretUpdate(CaretEvent e) { if (getFollowCaret()) { int line = textArea.getCaretLineNumber(); float percent = line / ((float)textArea.getLineCount()); textArea.computeVisibleRect(visibleRect); caretLineY = (int)(visibleRect.height*percent); if (caretLineY!=lastLineY) { repaint(0,lastLineY, getWidth(), 2); // Erase old position repaint(0,caretLineY, getWidth(), 2); lastLineY = caretLineY; } } }
@Override public void caretUpdate(CaretEvent e) { if (getFollowCaret()) { int line = textArea.getCaretLineNumber(); float percent = line / (float)(textArea.getLineCount()-1); textArea.computeVisibleRect(visibleRect); caretLineY = (int)(visibleRect.height*percent); if (caretLineY!=lastLineY) { repaint(0,lastLineY, getWidth(), 2); // Erase old position repaint(0,caretLineY, getWidth(), 2); lastLineY = caretLineY; } } }