Cross-Frame Drag And Drop

These classes let you drag objects between Java AWT Frames.

Why is this hard? Because of a quirk in the AWT, if you press the mouse button in one Component (the source) and then drag to another Component (the target), all the mouse events go to the source until the mouse button is released. So the target has no idea that anything's happening, even though the mouse is on top of it. (I have been told that Netscape on the Macintosh doesn't have this problem).

What can we do about it? Use a coordinator class to transfer the mouse events from the source to the appropriate target. Simple in principle, but there are some details that need to be taken care of:

Bad News: there is no reliable way to get the z-order of Frames. So if two Frames overlap, we might not be able to tell which one should get the mouse events.

Good News: by intercepting gotFocus() and show(), we can make guesses as to the correct z-order.

Bad News: this guessing is not portable. For example, in X windows, just because a window got the focus doesn't mean it's on top. But it works pretty well for Microsoft Windows. If you make changes to support a different platform, please let me know by sending email to kimbly - at - pobox - dot - com.

Here's a demo.
Here's the documentation.
Here's the source.

Here's the official drag and drop API from Javasoft.
Here's someone else's drag and drop, but it doesn't do frames.


Last updated sometime around 1996
Back to Kimberley's Code.
Back to Kimberley's Home Page.