MENU

Copy to Java Clipboard

TOC

Java clipboardcopy to

JavaSwingto a string withCopy to clipboardThe following is a sample source that will
JavaSwingTo manipulate the clipboard withClipboardto be used.
Clipboard gets it this way.

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

sample program

/**
 * Copy the specified string to the clipboard.
 * @param select string.
 */
public static void copyToClipboad(String select) {
    Clipboard clipboard = Toolkit.getDefaultToolkit()
            .getSystemClipboard();.
    StringSelection selection = new StringSelection(select);
    clipboard.setContents(selection, selection);
}    


Execution Result

◆Example of Execution

public static void main(String[] args) {
copyToClipboad("Chat&Messenger Chat and Messenger!!!") ;
}

◆Output result

*This is the result of executing "Paste" in a text editor.

Chat&Messenger Chat and Messenger!
TOC