Search code examples
javaswingcopy-pastejtextarea

Java - How to access highlighted material in a JTextArea


I have a JTextArea and I have a menu which allows you to cut, copy and paste information through the cut(), copy() and paste() methods. However, I want these methods to get the highlighted text from the text area and use that in the methods. Is this possible and how would you go about achieving this?


Solution

  • Use JTextArea.getSelectedText()