1

I think this should be really easy with JavaFX - so I must be missing the point somewhere. I have a simple drag-and-drop from a toolbar onto an AnchorPane which works fine, however I'm trying to find out exactly where the drop occurs to find out where to insert the new item within a group of Nodes already there. The event object DragEvent tells you the target object but not where it was dropped relative to the target ( only relative to the source ). I tried just listening to all mouse released events on the target but that isn't triggered for a drag onto an object. Anyone know how this should be done?

Mike Watts

1 Answer 1

1

You can either use the getSceneX/Y methods to obtain absolute coordinates of the location of the drop or install a listener on the AnchorPane which listens to DRAG_OVER DragEvents. The last position of the DRAG_OVER event that occured before it was dropped is the position where it was dropped.

2
  • Thanks for that Sebastian - yes I was confused by all the references to the 'source's scene' but that works nicely: targetPane.sceneToLocal(ev.getSceneX(), ev.getSceneY()) returns the point in the target pane ( where ev is the DragEvent object and targetPane is cast from ev.getTarget() ) Nov 20, 2012 at 13:06
  • i totally forgot about that method, yes. i'm glad that it works now.
    – zhujik
    Nov 20, 2012 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.