copy To Clipboard - Java Native OS

Java examples for Native OS:Clipboard

Description

copy To Clipboard

Demo Code


//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 content = "java2s.com";
        copyToClipboard(content);//from w w w . ja va 2s.c  om
    }

    public static synchronized void copyToClipboard(String content) {
        // get clipboard context
        Clipboard clipboard = Toolkit.getDefaultToolkit()
                .getSystemClipboard();
        StringSelection str = new StringSelection(content);
        clipboard.setContents(str, null);
    }
}

Related Tutorials