Here you can find the source of copyToClipBoard(String code, boolean displayMessage)
public static void copyToClipBoard(String code, boolean displayMessage)
//package com.java2s; //License from project: Apache License import javax.swing.JOptionPane; public class Main { /***********************************************************************/ public static void copyToClipBoard(String code) { copyToClipBoard(code, true);/*from w w w . j a v a 2 s . c om*/ } public static void copyToClipBoard(String code, boolean displayMessage) { java.awt.datatransfer.StringSelection selection = new java.awt.datatransfer.StringSelection(code); java.awt.Frame frame = new java.awt.Frame(); frame.getToolkit().getSystemClipboard().setContents(selection, selection); if (displayMessage) { JOptionPane.showMessageDialog(null, "Code copied to Clipboard", "Finished", JOptionPane.INFORMATION_MESSAGE); } frame.dispose(); } }