I'm currrently working on a GUI that needs to support dragging some application-specific objects from a selection area onto a work area (JPanel). It's currently working in a "click where to place the object, then click the Add button" mode, but that's not good enough.
The obvious approach is to use D&D (Java 6 or later) with a custom DataFlavor for the objects, but I'm struggling to find and decent documentation or examples of how to fit the whole thing together. The Oracle tutorials do a decent job of listing all the classs and methods involved, but not how to fit it all into an application. There are many code samples on the web, but many are pre-Java6, and the remainder use Swing's built-in support for some specific data flavors.
If you have any experience of doing this, or know of any useful info source, I'd love to hear from you.
ps: This is not homework ;)
Jump to Post
Hmm I found this code somewhere on the net as a question on a forum (lost the link now), but I patched it up and altered it (still not the best) but hopefully it will give you the basic idea:
Jump to Post
Since you are using custom components, you will probably be needing to call
TransferHandler.exportAsDragyourself to get the drag started because JPanel has no
setDragEnabledmethod. Instead, you will need to listen for mouse motion to detect the gesture that you want to begin the drag. I imagine you'll want …
All 7 Replies
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.