支持楼上的
/**
* Returns the zero-based offset of the caret.
*
* Note: The character to the right of the caret will have the
* same index value as the offset (the caret is between
* two characters).
*
* @return the zero-based offset of the caret.
*/
public int getCaretPosition()
/**
* Returns the zero-based offset of the caret.
*
* Note: The character to the right of the caret will have the
* same index value as the offset (the caret is between
* two characters).
*
* @return the zero-based offset of the caret.
*/
public int getCaretPosition()
the position of the text insertion caret for the text component >= 0JTextArea txtField = new JTextArea();
int pos = txtField.getCaretPosition();