Share this page 

Use the System ClipboardTag(s): AWT

import java.awt.datatransfer.*;
import java.awt.*;

public class Java2Clipboard implements ClipboardOwner {
    public static void main(String[] args) throws Exception {
      Java2Clipboard jc = new Java2Clipboard();
      Frame f = new Frame
         ("Open a text editor and paste the message from Java");

    public void toClipboard() {
      SecurityManager sm = System.getSecurityManager();
      if (sm != null) {
        try {
        catch (Exception e) {e.printStackTrace();}
      Toolkit tk = Toolkit.getDefaultToolkit();
      StringSelection st = 
           new StringSelection("Hello world from Java");
      Clipboard cp = tk.getSystemClipboard();
      cp.setContents(st, this);

    public void lostOwnership(Clipboard clip, Transferable tr) { 
       System.out.println("Lost Clipboard Ownership?!?");
NOTE: You can only use text (no graphic) with this functionality provided by the current JDK (1.4).