textArea.addCaretPosition(new CaretPosition(){
public void caretUpdate(CaretEvent e){
int caretPosition = e.getDot(); //== textArea.getCaretPosition();
int mark = e.getMark(); //有选择区域时的另一端,可能比getDot大,也可能小
}
}
getCaretPosition
public int getCaretPosition()Returns the position of the text insertion caret for the text component.
Returns:
the position of the text insertion caret for the text component >= 0