title: Clearing and editing Clipboard with Java
body: <p>I'm having some trouble interacting with the system clipboard (Editing it, clearing it, etc).</p>
  
  <p>I have the following code that when you build it and double click the Jar file, it opens up multiple browser windows for different sites of your choosing.</p>
  
  <pre><code>import java.awt.Robot;
  import java.awt.event.KeyEvent;
  import java.awt.datatransfer.*;
  import java.awt.Toolkit;
  
  import java.awt.datatransfer.DataFlavor;
  import java.awt.datatransfer.StringSelection;
  import java.awt.datatransfer.Transferable;
  import java.awt.datatransfer.UnsupportedFlavorException;
  
  //import clip.Clipboard.*;
  public class main {
  
  public static void main(String[] args) {
  
  //Open Chrome
  int keyControl = KeyEvent.VK_CONTROL;
  int keyT = KeyEvent.VK_T;
  
  // TODO Auto-generated method stub
       try {
       Process p = Runtime.getRuntime().exec("\"/Program Files (x86)/Google/Chrome/Application/chrome.exe\"");
  p.waitFor();
  System.out.println("Google Chrome launched!");
          } catch (Exception e) {
              e.printStackTrace();
          }
          try {
  
          Robot robot = new Robot();
  
          //Sites
          String site = "www.youtube.com";
          String site2 = "www.facebook.com";
  
          //SITE 1 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
          //Load Url
          StringSelection ss = new StringSelection(site);
          Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
          clpbrd.setContents(ss, null);
  
          //Enter URL
          robot.keyPress(KeyEvent.VK_CONTROL);
          robot.keyPress(KeyEvent.VK_V);
          robot.keyRelease(KeyEvent.VK_V);
          robot.keyRelease(KeyEvent.VK_CONTROL);
          robot.keyPress(KeyEvent.VK_ENTER);
          robot.keyRelease(KeyEvent.VK_ENTER);
  
          //Clear Clipboard
          String empty = "";
          StringSelection ss2 = new StringSelection(empty);
          clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
          clpbrd.setContents(ss2, null);
  
          //SITE 2  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
          //Load Url 
          StringSelection ss3 = new StringSelection(site2);
          clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
          clpbrd.setContents(ss3, null);
  
          //Create new tab
          robot.keyPress(keyControl);
          robot.keyPress(keyT);
          robot.keyRelease(keyControl);
          robot.keyRelease(keyT);
  
          //Enter URL
          robot.keyPress(KeyEvent.VK_CONTROL);
          robot.keyPress(KeyEvent.VK_V);
          robot.keyRelease(KeyEvent.VK_V);
          robot.keyRelease(KeyEvent.VK_CONTROL);
          robot.keyPress(KeyEvent.VK_ENTER);
          robot.keyRelease(KeyEvent.VK_ENTER);
          }
  
          catch (Exception e) {
          e.printStackTrace();
      }
  
      }
  }
  </code></pre>
  
  <p>When I try running this program, it opens the tabs but every tab is the same link. So it seems to be running into an issue with the clipboard. This is my first experience using the clipboard in my code.</p>
  
  <p>How do I make this work? I can't download any webdrivers/etc to solve the problem.</p>