The java.awt.datatransfer.Transferable interface

The java.awt.datatransfer.Transferable interface must be implemented by any class that will represent the data to be cut or pasted. It defines three methods:

 public abstract boolean isDataFlavorSupported(DataFlavor flavor)
 public abstract DataFlavor[] getTransferDataFlavors()
 public abstract Object getTransferData(DataFlavor flavor) 
  throws UnsupportedFlavorException, IOException

You can ask a Transferable object whether it supports a particular data flavor you want with isDataFlavorSupported() or you can ask it to list all the data flavors it supports with getTransferDataFlavors().

Note especially that one object may support multiple data flavors. For example, most objects should provide a plain text flavor as a lowest common denominator all applications can handle. However, the same data may also be available in an HTML flavor for applications that can handle the additional formatting.

Finally you request an object of a particular flavor with getTransferData(). If the flavor you request is not available an UnsupportedFlavorException is thrown.

Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
Last Modified April 23, 1997