import javax.swing.JTextArea;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.text.JTextComponent;
publicclass Main {
publicstaticvoid main(String[] argv) {
JTextComponent textComp = new JTextArea();
textComp.addCaretListener(new CaretListener() {
publicvoid 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);
}
});
}
}