Today's demo puts a drag image on each of the displayed drag-enabled components, and does so without modifying the original jar file. It also does so without any special knowledge of the components that are drag enabled. (Web start doesn't let you reference a file on another host, so you'll have to trust me when I say the original jar is used unmodified).
A few sights to take in after you've checked that "Turn on Drag and Drop" checkbox.
- Try a drag from each component.
- Try dragging a multiple, discontiguous selection from each component.
- Watch what happens when your drop is rejected.
- Move the main window, and drag some more. Notice the nice images across both windows (the original
mainhas simply been called twice).
The technique depends on all drag sources to use the default DragSource as the drag initiator. To date, all drags implemented within the JRE use the default, as do all the drag & drop examples I've seen on the web, so it always works in practice.
The global drag source listener technique used here could also be used to automatically switch the visible tab in a JTabbedPane, expand a node in a JTree, or even autoscroll components that don't implement Autoscroll. Watch for an upcoming article to address those options.