The JavaTM Tutorial
Previous Page Trail Contents Next Page Start of Tutorial Search

Trail: Drag and Drop

One day we'll have a trail here. For now, here are some links to resources and examples:
How to drag and drop with Java 2 (article in JavaWorld - March 1999)
Has step-by-step directions on adding drag-and-drop support to a component (a subclass of JLabel). Has a list of resources, including links to the downloadable example, javadoc, 1.2 drag-and-drop bugs, ...

How to drag and drop with Java 2, part 2 (article in JavaWorld - October 1999)
The second article in this drag-and-drop series explores how you can transfer data besides text. It also discusses the issues involved with developing a library of D&D-enabled project Swing components.

JavaBeans home page
Indirectly links to the Drag and Drop specification; might have other information related to Drag and Drop.

John Zukowski's example
From John: "Key points:
  • Drag from JTree, drop into JList.
  • Demonstrates using a custom data flavor for dragging the user data of the node
  • Can drop a file list into the JList."

Older example by John Zukowski
Here's John's description: "A D&D example I did back in July for beta 4. Probably needs a few updates for final (now that support is there for external Java dragging....) but a good start..."
Note: This example uses AWT components, not Swing components.
A rough example showing plain-text drag-and-drop with a JTextArea. Prints diagnostics.

A Drag and Drop Example by Sheetal Gupta
This example contains two lists. You can drag an item from either list and drop it onto the other list. Demonstrates that a single component can be both a Drag Source and a Drop Target. Prints diagnostics.
If you can recommend any other examples or resources, please send us mail with the subject drag and drop.

Previous Page Trail Contents Next Page Start of Tutorial Search