Java - copied clipboard contents disappear after program exit

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); // just to keep program running... Scanner scanner = new Scanner(System.in); scanner.nextLine(); 

edit: I am working on Ubuntu 10.10 with java version 1.6_20.

+2
source share
1 answer

It seems that the one (your program) puts the contents of the clipboard to the clipboard should be able to serve it in Ubuntu 10.10.

Installing glipper ( sudo apt-get install glipper ) works for me. It manages your clipboard. (This is an applet, so it seems that it needs to be added to the panel to run.)

0
source

Source: https://habr.com/ru/post/1346250/


All Articles