@Override public void setContents (String content) { try { StringSelection stringSelection = new StringSelection(content); java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, this); } catch (Exception ignored) { // Ignore JDK crashes sorting data flavors. } }
String myString = "This text will be copied into clipboard when running this code!"; StringSelection stringSelection = new StringSelection(myString); Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(stringSelection, null);
public void actionPerformed(ActionEvent actionEvent) { Clipboard clipboard = getToolkit().getSystemClipboard(); StringSelection ss = new StringSelection(log); clipboard.setContents(ss, ExceptionDialog.this); } });
@Override public void setContents (String content) { try { StringSelection stringSelection = new StringSelection(content); java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, this); } catch (Exception ignored) { // Ignore JDK crashes sorting data flavors. } }
public static void type(String characters) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection stringSelection = new StringSelection( characters ); clipboard.setContents(stringSelection, clipboardOwner); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); }
public static void setClipboardString(String text) { try { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable transferable = new StringSelection(text); clipboard.setContents(transferable, null); LOG.debug("String '{}' copied to clipboard", text); } catch (Exception e) { LOG.error("Failed copy string '{}' to clipboard", text, e); } } }
/** * Dumps a given text (either String or StringBuffer) into the Clipboard, with a default MIME type */ public static void putText(CharSequence data) { StringSelection copy = new StringSelection(data.toString()); getSystemClipboard().setContents(copy, copy); }
/** * Set the contents of the clipboard to a given value. * * @param str The new value of the clipboard contents */ protected void setClipboardContents(String str) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(str), null); }
String text = "Hello World"; StringSelection stringSelection = new StringSelection(text); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, stringSelection); Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL);
public static void toClipboard(String data) throws Exception { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection ss = new StringSelection(data); cb.setContents(ss, ss); }
public static void copyToClipboard(String data){ Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(new StringSelection(data), null); }
@Override public void actionPerformed(ActionEvent e) { // Get the clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // Set the sent text as the new content of the clipboard clipboard.setContents(new StringSelection(interpretedText1.getText()), null); } });
/** * Puts the supplied text into the system clipboard * * @param text The text to add to the clipboard */ public static void setClipboardText(String text) { try { Clipboard board = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection data = new StringSelection(text); board.setContents(data, null); } catch (HeadlessException e) { // ignore } } }
@Override public void actionPerformed(ActionEvent e) { // Get the clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // Set the sent text as the new content of the clipboard clipboard.setContents(new StringSelection(messageTextArea.getText()), null); } });
@Override public void actionPerformed(ActionEvent e) { // Get the clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // Set the sent text as the new content of the clipboard clipboard.setContents(new StringSelection(receivedText.getText()), null); } });
@Override public void actionPerformed(ActionEvent e) { // Get the clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // Set the sent text as the new content of the clipboard clipboard.setContents(new StringSelection(sentText1.getText()), null); } });
@Override public void actionPerformed(ActionEvent e) { // Get the clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // Set the sent text as the new content of the clipboard clipboard.setContents(new StringSelection(receivedText1.getText()), null); } });
@Override public void actionPerformed(ActionEvent e) { // Get the clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // Set the sent text as the new content of the clipboard clipboard.setContents(new StringSelection(sentText.getText()), null); } });
public static void clipboardCopy(String str) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new StringSelection(str), null); }
@Override public boolean setClipboardContents(String value) { return AccessController.doPrivileged( (PrivilegedAction<Boolean>) () -> { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); try { clipboard.setContents(new StringSelection(value), null); } catch (IllegalStateException exp) { // Some OSs might lock out access to clipboard, if another application uses it. // In this case, this exception is thrown return false; } return true; }); } }