JTextComponent textComp = new JTextArea(); textComp.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { // dot is the caret position int dot = e.getDot(); // mark is the non-caret end of the selection int mark = e.getMark(); } });