Caret

JTextComponent c = new JTextArea();

// Get position of the caret
c.getPosition();

// Get the character following the caret
if (c.getPosition() < c.getDocument().getLength()) {
    try {
        char ch = c.getText(c.getPosition(), 1).charAt(0);
    } catch (BadLocationException e) {
    }
}

// Move the caret
int newPosition = 0;
c.movePosition(newPosition);

// Set the caret color
c.setColor(Color.red);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.