Java examples for Swing:JTextComponent
Listening for Caret Movement Events in a JTextComponent
import javax.swing.JTextArea; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; import javax.swing.text.JTextComponent; public class Main { public void m() throws Exception { 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(); }/*from w ww.j a v a 2 s.com*/ }); } }