The java.awt.datatransfer Package

The java.awt.datatransfer package provides classes to support transfer of data to and from the system clipboard. Support for the clipboard is still in its infancy in Java 1.1. Only string data is supported, and only cut, copy, and paste. Other data types and drag and drop will be added in the future.

The java.awt.datatransfer.Transferable interface is implementod by classes that represent data to be transferred. It includes methods to determine the possible data flavors of the object and to retrieve the data itself.

The java.awt.datatransfer.DataFlavor class provides a MIME type based system for determining the type of data on the clipboard. For example, flavors include "text/plain; charset=unicode" and "application/x-java-serialized-object"

A java.awt.datatransfer.UnsupportedFlavorException is thrown when you ask a Transferable object to return its contents in an incompatible flavor.

The java.awt.datatransfer.Clipboard class allows the transfer of data through cut, copy, and paste operations. Although there's only one system clipboard, your program may create many different Clipboard objects for internal use.

For synchronization purposes each clipboard must be the exclusive property of one object. This object must implement the java.awt.datatransfer.ClipboardOwner interface. This interface declaes a single method, lostOwnership(), which is which is used to warn an object that it no longer owns the clipboard.

The java.awt.datatransfer.StringSelection class is the one concrete implementation of Transferable and ClipboardOwner included in Java 1.1. It allows you to transfer plain text to and from the system clipboard.


Previous | Next | Top
Last Modified April 20, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu