@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);
private void setClipboardImage(BufferedImage image) { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new ImageSelection(image), null); }
public void actionPerformed(ActionEvent actionEvent) { Clipboard clipboard = getToolkit().getSystemClipboard(); StringSelection ss = new StringSelection(log); clipboard.setContents(ss, ExceptionDialog.this); } });
/** * Copies the currently selected text to the system clipboard, with * any necessary style information (font, foreground color and background * color). Does nothing for {@code null} or empty selections. * * @see #copyAsStyledText(Theme) */ public void copyAsStyledText() { int selStart = getSelectionStart(); int selEnd = getSelectionEnd(); if (selStart==selEnd) { return; } // Get the selection as HTML String html = HtmlUtil.getTextAsHtml(this, selStart, selEnd); // Get the selection as RTF byte[] rtfBytes = getTextAsRtf(selStart, selEnd); // Set the system clipboard contents to the RTF selection. StyledTextTransferable contents = new StyledTextTransferable(html, rtfBytes); Clipboard cb = getToolkit().getSystemClipboard(); try { cb.setContents(contents, null); } catch (IllegalStateException ise) { UIManager.getLookAndFeel().provideErrorFeedback(null); } }
@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. } }
private void copy() { final GeneratedImage generatedImage = simpleLine2.getGeneratedImage(); if (generatedImage == null) { return; } final File png = generatedImage.getPngFile(); final Image image = Toolkit.getDefaultToolkit().createImage(png.getAbsolutePath()); final ImageSelection imgSel = new ImageSelection(image); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null); }
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); } } }
try { Robot robot = new Robot(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screen = new Rectangle( screenSize ); BufferedImage i = robot.createScreenCapture( screen ); TransferableImage trans = new TransferableImage( i ); Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); c.setContents( trans, this );
/** * 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); }
/** * 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(interpretedText1.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(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(receivedText1.getText()), null); } });