Example usage for java.awt.datatransfer StringSelection StringSelection

List of usage examples for java.awt.datatransfer StringSelection StringSelection

Introduction

In this page you can find the example usage for java.awt.datatransfer StringSelection StringSelection.

Prototype

public StringSelection(String data) 

Source Link

Document

Creates a Transferable capable of transferring the specified String .

Usage

From source file:Main.java

/**
 * Copy a String to clipborad//from w  w w.j  ava2s  .  c o m
 *
 * @param string
 */
public static void copyToClipboard(String string) {
    StringSelection stringSelection = new StringSelection(string);
    Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(stringSelection, null);
}

From source file:Main.java

public static void copyClipboard(String text) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection selection = new StringSelection(text);
    clipboard.setContents(selection, selection);

    return;/*from   ww w  .  j  a v a  2 s .  c om*/
}

From source file:Main.java

public static void copyToClipboard(String s) {
    StringSelection stringSelection = new StringSelection(s);
    Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(stringSelection, null);
}

From source file:Main.java

public static void setClipboard(String text) {
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), clipboardOwner);
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);
    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;/*w ww. j a v  a 2  s.co  m*/
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;//  w  w  w. j av a2 s.  c  o  m
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(clipboard.getData(DataFlavor.stringFlavor));
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);
    System.out.println(clipboard.getName());

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;//from www  .j  a v a2  s  .  com
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);
    System.out.println(clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor));

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;/*from w  ww.j  a  v  a 2s.  c  o  m*/
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);

    DataFlavor[] fla = clipboard.getAvailableDataFlavors();
    for (DataFlavor f : fla) {
        System.out.println(f);/*from  w ww.  j  a  v a2s  .  com*/
    }

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public Main() {
    Clipboard myClipboard = new Clipboard("name");

    // Implement Copy operation
    StringSelection contents = new StringSelection("data");
    clipboard.setContents(contents, this);

    // Implement Paste operation
    Transferable content = clipboard.getContents(this);
    String dstData;//from  w ww.ja v a  2 s . c o m
    try {
        dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
        System.out.println(clipboard.getData(DataFlavor.stringFlavor));
        System.out.println(dstData);
    } catch (Exception e) {
        e.printStackTrace();
    }
}