The Transferable Object

The java.awt.datatransfer.StringSelection class works well for transfers within the same JVM but experiences a ClassCastException when used in inter-JVM cases. To solve this problem, you will have to provide a custom Transferable object.

A custom Transferable object creates instances of the DataFlavors it wants to provide. The getTransferDataFlavors() method is directed by the Transferable interface to return an array of these flavors. To facilitate the implementation of isDataFlavorSupported(DataFlavor), create a java.util.List representation of this array.

This example provides two flavors, and you can use the two predefined DataFlavor flavors because you are simply transferring text data. You can use DataFlavor. stringFlavor ...

Get JavaBeans Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.