• Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag and Drop problem  RSS feed

 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I'm trying to implement DnD in a JTree
I have a problem when the user drags a node to a place it's not allowed to be dropped
The action doesn't seem to be ended properly

here's example code for discussion

http://www.java2s.com/Code/Java/Swing-JFC/DnDdraganddropJTreecode.htm

So, there's a drag source and a drop target
when you begin the drag the function dragGestureRecognized in the source get's called, this get's the ball rolling
when you drop the node, the function drop in the target get's called and if the target is invalid the target rejects the action
but in my code the source doesn't seem to get the message that the action has been terminated
if I try to drag another node the dragGestureRecognized function throws an exception that a drag operation is already in progress
how is this supposed to work?
I see the dragDropEnd function in the source, but it just seems to remove the old node if it's a MOVE operation, it seems like it should also handle the situation where the action get's canceled

Any Pointers??
Maybe just a little explaination of the flow of things
It's hard to trace this down in a debugger because so many events are being fired

TIA
Dave

[ August 21, 2006: Message edited by: Dave Robbins ]
[ August 21, 2006: Message edited by: Dave Robbins ]
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure......e.rejectDrop() "should" handle this and I see that it is in the code. Have you tried debugging and making sure that the drop is being rejected?
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, I just remembered your debugging comment ...if you dont want to debug, you can add a System.out.println("Drop Rejected") after the line of the code that rejects an invalid drop.
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brian

thanks for the reply
I seem to be getting inconsistent results
sometimes it works sometimes it doesn't
are you saying that e.rejectDrop() should notify both the drag source and the drop target that the action has been canceled?
that looks like the way it works but I'm having trouble and I don't want to guess how things work
I run their example code and it works flawlessly
BTW, I am using a debugger, it's just that some of those methods like dragover get called repeatedly so you can't stop in those

Dave
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!