Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Java 2 (formerly JDK 1.2) introduced the ability to transfer data using the familiar drag and drop (D&D) metaphor. In Java
2, D&D utilizes the underlying data-transfer mechanism introduced in JDK 1.1 (
java.awt.datatransfer) for use with the clipboard. Although this article discusses D&D operations in the context of GUI components, the specification
includes no restrictions that prevent direct programmatic operations.
To develop the D&D metaphor, Java 2 defines several new classes in package
java.awt.dnd. Please note: The GUI components used in this article are Swing components. In actuality, any subclass of
java.awt.Component may be used.
First, we'll look at how a GUI component representing the data source of a D&D operation maintains an association with a
Second, we'll examine how another GUI component representing the destination of the data of a D&D operation maintains an association
Finally, we'll wrap up with a
java.awt.datatransfer.Transferable object that encapsulates the data transferred between the
To download the source code in either zip or tar formats, see Resources.
Transferable object encapsulates data, it makes the data available to
DropTarget in a variety of
DataFlavors. For a local transfer within the same JVM (Java virtual machine),
Transferable provides an object reference.
However, for transfers to another JVM or to the native system, this wouldn't make any sense, so a
DataFlavor using a
java.io.InputStream subclass usually is provided. (While a discussion of data transfer classes is beyond the scope of this article, you will
find a linked list of previous JavaWorld articles on this topic in the Resources section below.)
When invoking a drag and drop operation, you may request various drag and drop actions. The
DnDConstants class defines the class variables for the supported actions:
DragSourceleaves the data intact
DragSourcedeletes the data upon successful completion of the drop
DragSourcewill perform either action requested by the
For a GUI component to act as the source of a D&D operation, it must be associated with five objects:
A common way to obtain a
DragSource object is to use one instance per JVM. Class method
DragSource.getDefaultDragSource will obtain a shared
DragSource object that is used for the lifetime of the JVM. Another option is to provide one
DragSource per instance of the
Component class. With this option, however, you accept responsibility for implementation.
Transferableinterface encapsulates transferred data