public class Main { public static void main(String[] argv) {
JTextComponent textComp = new JTextArea();
textComp.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) {
int dot = e.getDot();
System.out.println("dot is the caret position:" + dot);
int mark = e.getMark();
System.out.println("mark is the non-caret end of the selection: " + mark);
}
});
}
}