Copy data to system clipboard in Java

Description

The following code shows how to copy data to system clipboard.

Example


/*  ww  w .j  ava 2 s  .  co  m*/
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;

public class Main {
  public static void main(String[] argv) throws Exception {
  }

  // This method writes a string to the system clipboard.
  public static void copyToSystemClipboard(String str) {
    StringSelection ss = new StringSelection(str);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
  }
}




















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization