352
|
Chapter 9, Drag-and-Drop
#69 Translucent Drag-and-Drop
HACK
The quality of the interaction is greatly enhanced by the quantity of informa-
tion provided by the visual feedback. Another example is dragging a link
from the web browser to the desktop, where a translucent text box contain-
ing the link title and the URL is shown. Wouldn’t it be great to be able to do
the same in your application? Thankfully, Swing is perfectly suited for that
kind of job.
Translucence Rocks
Implementing a stylish drag-and-drop requires being able to draw a translu-
cent picture over any component. Every Swing frame contains several layers
on which components are painted. These layers serve many purposes,
among which is the drawing of pop-up menus over the regular components.
The higher-level layer is called the glass pane. A glass pane is a transparent
container you can use to draw over the entire UI, as seen in the hack that
turned dialogs into frame-anchored “sheets”
[Hack #44]. You will use it to
display translucent pictures during a drag-and-drop operation, as seen in
Figure 9-9.
Yet, translucent pictures do not cover all the needs of effective drag-and-
drop visual feedback. When the user drops a file on your application, you
can use a picture to indicate what the type of the file is. However, what pic-
ture will you use when the user wants to drag a text box into another box,
and expect the contents of the first box to be copied to the second? The best
Figure 9-9. A translucent picture as visual feedback for drag-and-drop

Get Swing Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.