Whenever a caret changes its position or if text is selected, a caret event is fired by a text component.
The class CaretEvent supports the methods getDot() and getMark() to retrieve the current location and the end position of a text selection, respectively.