Creating a Droppable Component

For a GUI component to act as the destination of a drag-and-drop, it must be associated with two objects:

      java.awt.dnd.DropTarget
      java.awt.dnd.DropTargetListener

The DropTarget

The DropTarget's constructor makes associations with both the DropTarget and the DropTargetListener objects. Alternatively, the DropTarget has setComponent() and addDropTargetListener() methods. Newly defined java.awt.Component methods are used by the DropTarget's constructors to inform the Component that it is now associated with the DropTarget.

The following are the additions to java.awt.Component:

public void setDropTarget( DropTarget dt )
Public DropTarget getDropTarget()

Let's define a droppable component. After you create a DropTarget ...

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.