看看getSelectedText()和select方法public String getSelectedText()
Returns the selected text contained in this TextComponent. If the selection is null or the document empty, returns null.Returns:the textThrows:IllegalArgumentException - if the selection doesn't have a valid mapping into the document for some reasonSee Also: setText(java.lang.String)selectpublic void select(int selectionStart,
                   int selectionEnd)
Selects the text found between the specified start and end locations. This call is provided for backward compatibility. It is routed to a call to setCaretPosition followed by a call to moveCaretPostion. The preferred way to manage selection is by calling those methods directly.Parameters:selectionStart - the start position of the text >= 0
selectionEnd - the end position of the text >= 0See Also: setCaretPosition(int), moveCaretPosition(int)