title: Copying to global clipboard does not work with Java in Ubuntu
body: <p>The following code from a standalone application works in ubuntu:</p>
  
  <pre><code>import java.awt.Toolkit;
  import java.awt.datatransfer.Clipboard;
  import java.awt.datatransfer.DataFlavor;
  import java.awt.datatransfer.StringSelection;
  import java.awt.datatransfer.UnsupportedFlavorException;
  import java.io.IOException;
  
  public class ClipboardTest {
  
      public static void main(String[] args) throws Exception {
          Clipboard clipBoard = Toolkit.getDefaultToolkit().getSystemClipboard();        
          // print the last copied thing
          System.out.println(clipBoard.getContents(null).getTransferData(DataFlavor.stringFlavor));
          StringSelection data = new StringSelection("NOW");
          clipBoard.setContents(data, data);
          // prints NOW
          System.out.println(clipBoard.getContents(null).getTransferData(DataFlavor.stringFlavor));
      }
  
  }
  </code></pre>
  
  <p>Pasting (Ctrl+V) into a different application results in nothing; I expect "NOW".  Calling the above code a second time gives the following exception:</p>
  
  <pre><code>Exception in thread "main" java.awt.datatransfer.UnsupportedFlavorException: Unicode String
      at sun.awt.datatransfer.ClipboardTransferable.getTransferData(ClipboardTransferable.java:160)
  </code></pre>
  
  <p>As a standalone application, this should work even after <a href="https://stackoverflow.com/a/8513761/194609">2011 security changes</a>. Copying via Ctrl+C from inside of a JTextField and then pasting elsewhere works.</p>
  
  <p>Have been unsuccessful on ubuntu 11.04 with both the latest java7 (jdk1.7.0_10) and jdk1.6.0_33; It <a href="https://stackoverflow.com/a/3592022/194609">should work</a> and does work as expected on windows 7 with the latest java7 and on mac osx 10.6 with java6_37. Also tried xubuntu 12.04 with those javas and it doesn't work there. Is this a linux/ubuntu bug?</p>
  
  <p><a href="https://stackoverflow.com/q/12707176/194609">Related question</a></p>