O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Carets

Carets represent the location where new text is inserted.

The Caret Interface

The Caret interface provides a number of useful features for dealing with text insertion and selection.

Properties

The Caret interface defines the properties shown in Table 21-1. The blinkRate property specifies the number of milliseconds between Caret blinks. A value of 0 indicates that the Caret shouldn’t blink at all.

Table 21-1. Caret properties

Property

Data type

get

is

set

default Value

blinkRate

int

·

 

·

 

dot

int

·

 

·

 

magicCaretPosition

Point

·

 

·

 

mark

int

·

   

selectionVisible

boolean

 

·

·

 

visible

boolean

 

·

·

 

The dot property is the current Caret position as an offset into the Document model. The mark is the other end of the current selection. If there is no selection, the value of mark is the same as dot. The selectionVisible property designates whether the current selection (if any) should be decorated by the component’s Highlighter.

The visible property indicates whether the Caret itself should be visible. This is almost always true when the Caret’s text component is editable and has focus but may not be in other situations.

magicCaretPosition is a Point used when moving among lines with uneven end positions to ensure that the up and down arrow keys produce the desired effect. For example, consider the following text:

Line 1 is long
Line 2
Line 3 is long

If the caret was initially positioned before the o in long in line 3, you’d expect the up arrow key to move the caret to the end of line 2. A second up ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required