I have a JTextArea and would like to have a button that when clicked will copy the entire contents of the JTextArea to the System clipboard so that I can do Ctrl-V in any other program. I have tried this but with no luck. Here is an example of something I’ve tried:
StringSelection stringSelection = new StringSelection("This is a clipping");
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents( stringSelection, null );
ClipBoardrequires a ClipboardOwner for the copy action to take effect. This interface is often implemented by the current “pasting” class:Example