Java examples for Native OS:Clipboard
set Text To Clipboard
//package com.java2s; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; public class Main { public static void main(String[] argv) throws Exception { String text = "java2s.com"; setTextToClipboard(text);//from ww w. j a va 2s . co m } public static void setTextToClipboard(String text) { StringSelection stringSelection = new StringSelection(text); Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard(); cp.setContents(stringSelection, stringSelection); } }