Class DefaultCaret

All Implemented Interfaces:
Shape, Serializable, Cloneable, EventListener, Caret, FocusListener, MouseListener, MouseMotionListener

public class DefaultCaret extends Rectangle implements Caret, FocusListener, MouseListener, MouseMotionListener
Emulator for DefaultCaret — the caret every text component installs, and the one its caret methods read and write:
DefaultCaret caret = (DefaultCaret) logArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);   // follow appends from a worker too
logArea.getCaret().setDot(logArea.getDocument().getLength());

Dot and mark follow the component's Document as the JDK's do: under the default UPDATE_WHEN_ON_EDT an edit on the UI thread moves them, an edit from a background thread only clamps them. A NavigationFilter installed on the component sees every setDot / moveDot, the user's clicks and arrow keys included, since those arrive from the browser through the same two methods.

The caret registers no focus or mouse listener on its component, unlike the JDK's: each would install a peer bridge costing a round trip per focus change or click, and the browser already places the caret. So focusGained(FocusEvent) and the mouse callbacks run only when called, isSelectionVisible() stays false, and paint(Graphics) and the blink timer do nothing.

See Also: