Skip to Main Content
Java Swing, 2nd Edition
book

Java Swing, 2nd Edition

by Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole
November 2002
Intermediate to advanced content levelIntermediate to advanced
1278 pages
38h 26m
English
O'Reilly Media, Inc.
Content preview from Java Swing, 2nd Edition

Finishing Touches

With the DnD API, we can add a few more features to help us achieve the goal of user interface maturity. Since we can’t drop our objects on other leaves, we really should keep the drag cursor consistent. If we’re over a folder, we can accept the drag and show the “ok to drop here” cursor. If we’re anywhere else, we’ll reject the drag and show the “no drop” version. The current implementation of our handlers allows only nodes to be moved. We can include support for “copy or move” drags. (We can also keep our cursor in sync with the new support so users know whether they’re copying or moving.) Once all this is working, we should also set up autoscrolling on our tree to give the user access to any off-screen parts of the tree.

Dynamic Cursors

If your application can use the new DnD support built into the 1.4 release, you shouldn’t have to worry about cursor management. If you’re using one of the older SDKs or building fancier custom support, read on.

The DnD package ships with some standard cursors for indicating “ok to drop” and “not ok to drop.” These cursors are displayed automatically when you accept( ) or reject( ) an item as it is dragged over potential drop targets. Here’s a look at the dragEnter( ) and dragOver( ) event handlers that check to see whether the mouse is over a folder in the tree. If it’s not, we reject the drag. This rejection causes the cursor to update its appearance. (Note that with the new cursor features in Java 2, you can define your own ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Threads, 3rd Edition

Java Threads, 3rd Edition

Scott Oaks, Henry Wong

Publisher Resources

ISBN: 0596004087Errata PageSupplemental Content