StringSelection is a "convenience" class that can be used for copy and paste operations on Unicode text strings. For example, you could place a string on the system's clipboard with the following code:
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection s = new StringSelection( "Be safe when you cut and paste."); c.setContents(s, s);
public class java.awt.datatransfer.StringSelection extends java.lang.Object implements java.awt.datatransfer.ClipboardOwner, java.awt.datatransfer.Transferable { // Constructor public StringSelection(String data); // Instance Methods public synchronized Object getTransferData (DataFlavor flavor) throws UnsupportedFlavorException, IOException; public synchronized DataFlavor[] getTransferDataFlavors(); public boolean isDataFlavorSupported (DataFlavor flavor); public void lostOwnership (Clipboard clipboard, Transferable contents); }
The string to be placed in a clipboard.
Constructs a StringSelection object from the given string.
The requested flavor for the returned data, which can be either DataFlavor.stringFlavor or DataFlavor.plainTextFlavor.
The string that the StringSelection was constructed with. This is returned either as a String object or a Reader object, depending on the flavor requested.
If the requested flavor is not supported.
If a Reader representing the string could not be created.
Transferable.getTransferData(DataFlavor)
Returns the string this StringSelection represents. This is returned either as a String object or a Reader object, depending on the flavor requested.
An array of the data flavors the StringSelection supports.
Transferable.getTransferDataFlavors()
DataFlavor.stringFlavor and DataFlavor.plainTextFlavor are returned.
The flavor in question.
true if flavor is supported; false otherwise.
Transferable.isDataFlavorSupported(DataFlavor)
The clipboard whose contents are changing.
The contents that were on the clipboard.
ClipboardOwner.lostOwnership(Clipboard, Transferable)
Does nothing.
Clipboard, ClipboardOwner, DataFlavor, String, Transferable