In the previous section, you saw how to take advantage of the basic drag-and-drop support in Swing. In this section, we’ll show you how to configure any component as a drag source. In the next section, we’ll discuss drop targets and present a sample component that is both a source and a target for images.
To customize the drag-and-drop behavior of a Swing component, subclass the
TransferHandler class. First, override the
getSourceActions method to indicate which actions (copy, move, link) your component supports. Next, override the
createTransferable method that produces a
Transferable object, following the same process that you use for copying to the clipboard.
In our sample program, we drag images out of a
JList that is ...