Skip to main content

Problem with JTree DnD

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2010-11-19

I am really stuck on this and desperately need help.

I am programming Drag and Drop on a JTree using TransferHandler. One of the things my canImport method checks for is trying to drop a parent on a child (clearly a no-no). The method correctly checks for this condition and returns FALSE. The cursor shows the appropriate circle with a line thru it indicating you can't drop here.

However, if I go ahead and release the mouse anyways, for some reason it goes ahead and tries to make the transfer. It calls my exportDone method first (since that method doesn't know any better, it goes ahead and unhooks the node from the tree), and then calls my importData method. Since the node us already unhooked from the tree, I am now screwed.

What am I doing wrong? Why does the transfer ignore my canImport returning false and go ahead and try to transfer anyways?

Any help is greatly appreciated ... I am really screwed here.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-11-19

OK - found it.
When exportDone is called there is an 'action' parameter passed in ... and if canImport has returned FALSE then the action is 0 - meaning do nothing. Unfortunately, none of the examples I found on the net demonstrated this.

IMHO, it is rather silly to go thru the bother of a callback just to say "don't do anything" - but I guess there are complexities at work that I don't understand.