不是MouseMotionListener,大哥是光标,不是鼠标textArea.addCaretPosition(new CaretPosition(){ public void caretUpdate(CaretEvent e){ int caretPosition = e.getDot(); //== textArea.getCaretPosition(); int = 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
public void caretUpdate(CaretEvent e){
int caretPosition = e.getDot(); //== textArea.getCaretPosition();
int = e.getMark(); //有选择区域时的另一端,可能比getDot大,也可能小
}
}});
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