I need to select a piece of text in JTextArea. How can I do it?...
Use setCaretPosition(selectionStart) and then moveCaretPosition(selectionEnd) . This is described in the JTextComponent javadoc
setCaretPosition(selectionStart)
moveCaretPosition(selectionEnd)