![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e998. Moving the Caret of a JTextComponentJTextComponent 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);
e1000. Using the Selection of a JTextComponent
© 2002 Addison-Wesley. |