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