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);

One thought on “Caret”

  1. Hey there! I just wanted to ask if you ever have any trouble with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no data backup. Do you have any solutions to prevent hackers?

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.