I would like to replace the contents of the system clipboard with my Java code, but the copied content disappears after exiting the Java program. How can I make data persistent?
Thank you very much.
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable t = clipboard.getContents(null); if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { String data = (String) t.getTransferData(DataFlavor.stringFlavor); System.out.println(data); } StringSelection stringSelection = new StringSelection("Replaced Text"); clipboard.setContents(stringSelection, null);
edit: I am working on Ubuntu 10.10 with java version 1.6_20.
source share