- java.lang.Object
- 
- java.awt.datatransfer.Clipboard
 
- 
 public class Clipboard extends Object A class that implements a mechanism to transfer data using cut/copy/paste operations.FlavorListeners may be registered on an instance of the Clipboard class to be notified about changes to the set ofDataFlavors available on this clipboard (seeaddFlavorListener(java.awt.datatransfer.FlavorListener)).- Since:
- 1.1
- See Also:
- Toolkit.getSystemClipboard(),- Toolkit.getSystemSelection()
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected TransferablecontentsContents of the clipboard.protected ClipboardOwnerownerThe owner of the clipboard.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFlavorListener(FlavorListener listener)Registers the specifiedFlavorListenerto receiveFlavorEvents from this clipboard.DataFlavor[]getAvailableDataFlavors()Returns an array ofDataFlavors in which the current contents of this clipboard can be provided.TransferablegetContents(Object requestor)Returns a transferable object representing the current contents of the clipboard.ObjectgetData(DataFlavor flavor)Returns an object representing the current contents of this clipboard in the specifiedDataFlavor.FlavorListener[]getFlavorListeners()Returns an array of all theFlavorListeners currently registered on thisClipboard.StringgetName()Returns the name of this clipboard object.booleanisDataFlavorAvailable(DataFlavor flavor)Returns whether or not the current contents of this clipboard can be provided in the specifiedDataFlavor.voidremoveFlavorListener(FlavorListener listener)Removes the specifiedFlavorListenerso that it no longer receivesFlavorEvents from thisClipboard.voidsetContents(Transferable contents, ClipboardOwner owner)Sets the current contents of the clipboard to the specified transferable object and registers the specified clipboard owner as the owner of the new contents.
 
- 
- 
- 
Field Detail- 
ownerprotected ClipboardOwner owner The owner of the clipboard.
 - 
contentsprotected Transferable contents Contents of the clipboard.
 
- 
 - 
Constructor Detail- 
Clipboardpublic Clipboard(String name) Creates a clipboard object.- Parameters:
- name- for the clipboard
- See Also:
- Toolkit.getSystemClipboard()
 
 
- 
 - 
Method Detail- 
getNamepublic String getName() Returns the name of this clipboard object.- Returns:
- the name of this clipboard object
- See Also:
- Toolkit.getSystemClipboard()
 
 - 
setContentspublic void setContents(Transferable contents, ClipboardOwner owner) Sets the current contents of the clipboard to the specified transferable object and registers the specified clipboard owner as the owner of the new contents.If there is an existing owner different from the argument owner, that owner is notified that it no longer holds ownership of the clipboard contents via an invocation ofClipboardOwner.lostOwnership()on that owner. An implementation ofsetContents()is free not to invokelostOwnership()directly from this method. For example,lostOwnership()may be invoked later on a different thread. The same applies toFlavorListeners registered on this clipboard.The method throws IllegalStateExceptionif the clipboard is currently unavailable. For example, on some platforms, the system clipboard is unavailable while it is accessed by another application.- Parameters:
- contents- the transferable object representing the clipboard content
- owner- the object which owns the clipboard content
- Throws:
- IllegalStateException- if the clipboard is currently unavailable
- See Also:
- Toolkit.getSystemClipboard()
 
 - 
getContentspublic Transferable getContents(Object requestor) Returns a transferable object representing the current contents of the clipboard. If the clipboard currently has no contents, it returnsnull. The parameter Object requestor is not currently used. The method throwsIllegalStateExceptionif the clipboard is currently unavailable. For example, on some platforms, the system clipboard is unavailable while it is accessed by another application.- Parameters:
- requestor- the object requesting the clip data (not used)
- Returns:
- the current transferable object on the clipboard
- Throws:
- IllegalStateException- if the clipboard is currently unavailable
- See Also:
- Toolkit.getSystemClipboard()
 
 - 
getAvailableDataFlavorspublic DataFlavor[] getAvailableDataFlavors() Returns an array ofDataFlavors in which the current contents of this clipboard can be provided. If there are noDataFlavors available, this method returns a zero-length array.- Returns:
- an array of DataFlavors in which the current contents of this clipboard can be provided
- Throws:
- IllegalStateException- if this clipboard is currently unavailable
- Since:
- 1.5
 
 - 
isDataFlavorAvailablepublic boolean isDataFlavorAvailable(DataFlavor flavor) Returns whether or not the current contents of this clipboard can be provided in the specifiedDataFlavor.- Parameters:
- flavor- the requested- DataFlavorfor the contents
- Returns:
- trueif the current contents of this clipboard can be provided in the specified- DataFlavor;- falseotherwise
- Throws:
- NullPointerException- if- flavoris- null
- IllegalStateException- if this clipboard is currently unavailable
- Since:
- 1.5
 
 - 
getDatapublic Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException Returns an object representing the current contents of this clipboard in the specifiedDataFlavor. The class of the object returned is defined by the representation class offlavor.- Parameters:
- flavor- the requested- DataFlavorfor the contents
- Returns:
- an object representing the current contents of this clipboard in
         the specified DataFlavor
- Throws:
- NullPointerException- if- flavoris- null
- IllegalStateException- if this clipboard is currently unavailable
- UnsupportedFlavorException- if the requested- DataFlavoris not available
- IOException- if the data in the requested- DataFlavorcan not be retrieved
- Since:
- 1.5
- See Also:
- DataFlavor.getRepresentationClass()
 
 - 
addFlavorListenerpublic void addFlavorListener(FlavorListener listener) Registers the specifiedFlavorListenerto receiveFlavorEvents from this clipboard. Iflistenerisnull, no exception is thrown and no action is performed.- Parameters:
- listener- the listener to be added
- Since:
- 1.5
- See Also:
- removeFlavorListener(java.awt.datatransfer.FlavorListener),- getFlavorListeners(),- FlavorListener,- FlavorEvent
 
 - 
removeFlavorListenerpublic void removeFlavorListener(FlavorListener listener) Removes the specifiedFlavorListenerso that it no longer receivesFlavorEvents from thisClipboard. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to thisClipboard. Iflistenerisnull, no exception is thrown and no action is performed.- Parameters:
- listener- the listener to be removed
- Since:
- 1.5
- See Also:
- addFlavorListener(java.awt.datatransfer.FlavorListener),- getFlavorListeners(),- FlavorListener,- FlavorEvent
 
 - 
getFlavorListenerspublic FlavorListener[] getFlavorListeners() Returns an array of all theFlavorListeners currently registered on thisClipboard.- Returns:
- all of this clipboard's FlavorListeners or an empty array if no listeners are currently registered
- Since:
- 1.5
- See Also:
- addFlavorListener(java.awt.datatransfer.FlavorListener),- removeFlavorListener(java.awt.datatransfer.FlavorListener),- FlavorListener,- FlavorEvent
 
 
- 
 
-