List of usage examples for java.awt.datatransfer Transferable toString
public String toString()
From source file:org.languagetool.gui.Main.java
private String getClipboardText() { // get text from clipboard or selection: Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection(); if (clipboard == null) { // on Windows clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); }/*from w ww . java 2s. c om*/ String s; Transferable data = clipboard.getContents(this); try { if (data != null && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) { DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor(); try (Reader sr = df.getReaderForText(data)) { s = StringTools.readerToString(sr); } } else { s = ""; } } catch (Exception ex) { s = data.toString(); } return s; }