
CHAPTER 12
Thejava.awt.dnd Package
The java.awt.dnd package contains classes and interfaces that support data transfer
thr ough the drag-and-drop metaphor; the package is new in Java 1.2. This
functionality is built upon the data transfer framework of the java.awt.datatransfer
package.
A DragSource object is a proxy for an object that initiates a drag, while a DropTarget
object is a proxy for an object that wishes to accept drops. All inter-object commu-
nication during the drag process is done through the various event classes defined
by this package. Figure 12-1 shows the class hierarchy of this package. See Chap-
ter 6, Data Transfer, for more details on drag-and-drop.
Autoscroll Ja va 1.2
java.awt.dnd
This interface allows a scrollable component to scroll itself as part of the drag-and-drop
pr ocess, so that a user can drop an object anywhere within the component’s scrollable
content. Consider, for example, the problem of cutting a paragraph of text from the top
of a long document and dragging it down to the bottom of the same document. While
the drag-and-drop operation is in progr ess, the user obviously cannot operate the
scr ollbar, since the mouse is already in use. So some other technique is necessary to
enable scrolling during a drag-and-drop operation.
The Autoscroll inter face enables this specialized form of scr olling. When an object is first
dragged over a component that implements