xiaozhuai
12/2/2016 - 9:58 AM

groovy clipboard utlis

groovy clipboard utlis

import java.awt.datatransfer.StringSelection
import java.awt.Toolkit
import java.awt.datatransfer.*

class ClipboardUtils{
    static final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()

    static void setClipboardContents(final String contents){
        clipboard.setContents(new StringSelection(contents), null)
    }

    static String getClipboardContents(){
        return clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor)
    }
}