3

I have a MouseMotionListener and in the mouseDragged method I have a boolean that turns to true. The problem is I have no idea how to get it to turn back to false once the drag is over. Is there a way to do this? Any help is appreciated.

moomoohk
  • 483
  • 1
  • 8
  • 23

1 Answers1

3

for SWT: you could add a MouseListener with the method public void mouseUp(MouseEvent arg0) and set the boolean to false. See here: MouseListener Example

Or if you use swing, this is helpful (with public void mouseReleased(MouseEvent e)): MouseListener

Baz
  • 36,440
  • 11
  • 68
  • 94
  • The thing is though I'm not releasing the mouse, just "pausing" the drag, as in I drag, stop dragging, then continue all while having the button pressed. What happens right now is that the window will maintain momentum until i release the mouse. I'm looking to find out if there's a way to stop the drag without letting go of the mouse. – moomoohk Jun 17 '12 at 11:08
  • you could use a timer to check the mouse position during drag every ms or so, if the mouse position is the same for two checks, assume mouse move ended and set boolean. here is a reference for the timer of swing: [link](http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html). – Baz Jun 17 '12 at 11:30
  • That's what I was thinking of doing. I just wanted to see if there was a more direct way. Thanks for the help – moomoohk Jun 17 '12 at 12:29
  • Maybe there is another way, but I can't think of any. It's not ideal, but will do the job... – Baz Jun 17 '12 at 12:46