Globmont Globmont - 8 months ago 25
Java Question

How would I make a paste from java using the system clipboard?

I want to make a paste from the system clipboard in java. How would I do this?


While the robot class would work, it's not as elegant as using the system clipboard directly, like this:

private void onPaste(){
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable t = c.getContents(this);
    if (t == null)
    try {
        jtxtfield.setText((String) t.getTransferData(DataFlavor.stringFlavor));
    } catch (Exception e){