Skip to Main Content
Java Swing, 2nd Edition
book

Java Swing, 2nd Edition

by Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole
November 2002
Intermediate to advanced content levelIntermediate to advanced
1278 pages
38h 26m
English
O'Reilly Media, Inc.
Content preview from Java Swing, 2nd Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Threads, 3rd Edition

Java Threads, 3rd Edition

Scott Oaks, Henry Wong

Publisher Resources

ISBN: 0596004087Errata PageSupplemental Content