title: Java Clipboard on Linux (text only), some programs can read it, others can't, why
body: <p>When my Java-based application (not a browser-based applet) copies plain text to the system clipboard on Linux, many programs are not able to access the clipboard data, but some are.</p>
  
  <p>Here's the simplest test I could make:</p>
  
  <pre><code>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) {
      }
    }
  } 
  </code></pre>
  
  <p>While this program is running, File > Paste in OpenOffice (LibreOffice 3.5.7.2) is able to access the text it placed on the system clipboard.  But using File > Paste in Gnome Terminal, Mozilla Thunderbird &amp; Firefox, and many other programs can not.  The Paste option is gray, as if the clipboard is empty.</p>
  
  <p>How can I make my Java program publish plain text to the system clipboard on Linux (testing on Ubuntu 12.04) so all programs can access it?</p>