| |
e998. Moving the Caret of a JTextComponent
JTextComponent c = new JTextArea();
// Get position of the caret
c.getCaretPosition();
// Get the character following the caret
if (c.getCaretPosition() < c.getDocument().getLength()) {
try {
char ch = c.getText(c.getCaretPosition(), 1).charAt(0);
} catch (BadLocationException e) {
}
}
// Move the caret
int newPosition = 0;
c.moveCaretPosition(newPosition);
// Set the caret color
c.setCaretColor(Color.red);
e999.
Setting the Blink Rate of a JTextComponent's Caret
e1000.
Using the Selection of a JTextComponent
© 2002 Addison-Wesley.
| | |