When my Java-based application (and not the browser-based applet) copies plain text to the Linux system clipboard, many programs cannot access the clipboard data, but some of them.
Here is the simplest test I could do:
import java.awt.datatransfer.*; import java.awt.Toolkit; import java.io.*; public final class PasteTest { public static void main (String... args) { String mytext = "This is a test message, testing, 1, 2, 3...."; StringSelection sel = new StringSelection(mytext); Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); clip.setContents(sel, null); try { Thread.sleep(1000); } catch (Exception e) { } } }
While this program is running, File> Paste in OpenOffice (LibreOffice 3.5.7.2) has access to the text that it places on the system clipboard. But using File> Paste in Gnome Terminal, Mozilla Thunderbird and Firefox and many other programs cannot. The Paste option is gray, as if the clipboard is empty.
How can I get my Java program to publish plain text on the Linux system clipboard (tested on Ubuntu 12.04) so ββthat all programs can access it?
source share