This article will give you a good understanding of how to send and get information from the clipboard in Java. You'll also learn how to deal with the different data flavors available. Finally, we'll cover the multiple personalities of clipboards and how they provide support for more than one data flavor.
Java offers two types of clipboards: local and system. Local clipboards are only available inside the virtual machine that your applet or application is running. However, unlike some operating systems that limit you to only one clipboard, Java allows you to have as many local clipboards as you desire. Accessing a particular local clipboard is as easy as referring to it by name.
System clipboards are directly linked with the peer operating system, allowing your application to transfer information among any applications running under that operating system. One disadvantage of using the system clipboard is that you can only transfer text data. Other types of objects are not supported by the system clipboard. With any luck, this issue will be addressed in the next release of the JDK.
Before we go any further, let's take a look at all the classes involved in manipulating the clipboard. These classes, listed in the table below, are all part of the java.awt.datatransfer package.
|Class||Deals with everything that is a transferable|
|Interface||Every class that deals with the clipboard must implement this interface. This interface is used to notify when the data originally placed in the clipboard has been overwritten|
|Class||Represents all the data types that transferable support|
|Class||One type of transferable that is supplied with Java|
|Interface||Wrapper to objects passed to the clipboard|
|Class||Exception thrown by transferable for an unsupported data flavor|