I want to set the user's clipboard to a string in a Java console application. Any ideas?
Use the Toolkit
to get the system clipboard. Create a StringSelection
with the String
and add it to the Clipboard
.
Simplified:
StringSelection selection = new StringSelection(theString);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);