O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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
Translucent Drag-and-Drop #69
Chapter 9, Drag-and-Drop
|
351
HACK
Figure 9-7 shows what the visual feedback looks like on Windows.
Not only does this look bad, it also conveys very little information. Mac OS X
users are used to a much richer environment, and why should Windows or
Linux users expect less? As an example of what can be done, Safari—Mac
OS X’s default web browser—shows a translucent thumbnail of the picture
you are dragging. Figure 9-8 shows what this looks like in action.
Figure 9-7. Default drag-and-drop visual feedback on Windows
Figure 9-8. Mac OS X provides great looking visual feedback for drag-and-drop

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required