• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Getting the mouse drag release event on a canvas ?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have scene consisting of a single canvas. I'm using the canvas context to draw graphics on. I'm tracking the mouse location for input. Everything is working fine but I can't get the mouse drag release event to respond. I'm using the mouse press / release events to track button pushes. The standard press / release mouse events respond fine but after performing a drag the mouse drag release never happens.



Here is the function for my mouse events. It should print "drag release" but the mouse drag release event isn't happening.



 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are filtering MOUSE_RELEASED events and consuming them.  My guess is that this may cause MOUSE_DRAG_RELEASED events not to be triggered.  (I don't know for sure as I didn't try executing your code snippet, but it just a guess).  I recommend not consuming events unless you know you need to consume them as consuming events (especially in filters) can prevent standard event handlers from being executed.  If you capture events instead of letting them bubble then you run the risk of disabling default functionality (sometimes you want to disable default functionality, which is why filters are there, but most of the time you don't, which is why they are not often used).  

For background see the info on bubbling and filtering at: https://docs.oracle.com/javase/8/javafx/events-tutorial/processing.htm

I'm not sure why you use event filters rather than event handlers as the Oracle drag and drop tutorial recommends:
 https://docs.oracle.com/javase/8/javafx/events-tutorial/drag-drop.htm#CHDJFJDH
It shouldn't really matter either way in this case, but I would think using event handlers would be generally preferred.

It is also odd that you are setting filters on the scene.  If you are working a user interacting with a drawing on a canvas, then setting your event filters or handlers on the canvas itself rather than the scene would seem to be preferable.  If the scene contains other widgets such as tool drawing tool icons and controls, then setting an overall event filter on the scene may prevent those drawing tools and icons from receiving events that they would be expected to get to allow their actions to work.
 
John Damien Smith
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crossposts:
 https://community.oracle.com/thread/4030544
 http://stackoverflow.com/questions/43038567/javafx-fire-mouse-release-event-after-drag-over
Please note the JavaRanch policy on cross posts, thanks:
 https://coderanch.com/wiki/660346/Forthright-Cross-Posting-Sites
 
Joe Smithh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Damien Smith wrote:You are filtering MOUSE_RELEASED events and consuming them.  My guess is that this may cause MOUSE_DRAG_RELEASED events not to be triggered.  (I don't know for sure as I didn't try executing your code snippet, but it just a guess).  I recommend not consuming events unless you know you need to consume them as consuming events (especially in filters) can prevent standard event handlers from being executed.  If you capture events instead of letting them bubble then you run the risk of disabling default functionality (sometimes you want to disable default functionality, which is why filters are there, but most of the time you don't, which is why they are not often used).  

For background see the info on bubbling and filtering at: https://docs.oracle.com/javase/8/javafx/events-tutorial/processing.htm

I'm not sure why you use event filters rather than event handlers as the Oracle drag and drop tutorial recommends:
 https://docs.oracle.com/javase/8/javafx/events-tutorial/drag-drop.htm#CHDJFJDH
It shouldn't really matter either way in this case, but I would think using event handlers would be generally preferred.

It is also odd that you are setting filters on the scene.  If you are working a user interacting with a drawing on a canvas, then setting your event filters or handlers on the canvas itself rather than the scene would seem to be preferable.  If the scene contains other widgets such as tool drawing tool icons and controls, then setting an overall event filter on the scene may prevent those drawing tools and icons from receiving events that they would be expected to get to allow their actions to work.



Okay , thanks for the advice. I got rid of the consume events which helped because that was causing other nodes to not respond to events. What the problem seems to be is that when you drag a control you need to have a target for the drop. What I wanted to do was create a control that could respond to its own drag event but it looks like that may not be possible. Ultimately what I did was call the drag detect on the canvas then use the scene as the drag drop target. Basically this works. Where canvas is the draggable control and scene is target. I'm not actually moving the canvas I'm just using it to get the mouse events.




 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic