
350
|
Chapter 9, Drag-and-Drop
#69 Translucent Drag-and-Drop
HACK
H A C K
#69
Translucent Drag-and-Drop Hack #69
The Java implementation of drag-and-drop offers poor visual feedback. This
hack shows how to provide more information and a better-looking response
to the user.
A good way to create user-friendly interfaces is to provide the ability to drag-
and-drop almost anything from, within, and onto those interfaces. Mac OS X
is a perfect example of a good drag-and-drop use. Every time I try to drag
something to drop it onto something else, it just works. AWT, and there-
fore Swing, let applications implement drag-and-drop but lack something
Mac OS X already offers: really cool visual feedback to let the user know
what’s going on.
A Rather Boring Cursor
J2SE has offered drag-and-drop facilities since version 1.2. All the necessary
classes and interfaces can be found in the package
java.awt.dnd. Although
not very easy to use at first, this package provides powerful features you can
use to greatly improve the usability of your applications. Unfortunately, the
Java drag-and-drop framework offers little visual feedback. In fact, the only
feedback the user can get is a simple mouse cursor. For instance, you can
show that a drag-and-drop operation is in progress with the following line of
code:
dropTarget.setCursor(DragSource.DefaultMoveDrop);
Figure 9-6. Handling dropped images by supporting Pict format