public String getClipboardContents() { Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { return (String) contents.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return ""; } } return ""; }
public void copySelection() { Toolkit.getDefaultToolkit() .getSystemClipboard() .setContents(new StringSelection(getSelectedText()), this); }