The function indexOf(storeText) Returns the index within this stringof the first occurrence of the specified substring.... try using theJTextComponent function cut() and paste() or getSelectionStart()