ListenCaretEvent

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.