• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

method for mouse when the mouse stopped Dragging but is not released yet

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I am interested how to do this thing:
for e.g., I want to draw a square when the mouse stopped Dragging but is not released yet? I tried mouse pressed but it calls it only at the beginning. So, I have no idea, any help?
Cheers in advance!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can’t think of any offhand, even though I once had to program the same sort of thing. There are 7 mouse methods that I can remember, in the MouseListener interface and in MouseMotionListener. They are for when the mouse is
  • clicked
  • depressed
  • released
  • enters the Component
  • leaves the Component
  • moved
  • and dragged
  • I think mouseDragged is the most likely to work. Try the two opposite corners with pressed giving you one pair of x, y (first corner) and dragged (repeatedly) giving you the x, y for the other corner.
     
    Bartender
    Posts: 5167
    11
    Netbeans IDE Opera Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you want to draw a square (rectangle?) when the drag is stopped but don't want to draw while the mouse is still being dragged, you need to start by defining 'stopped' in terms of time/duration and drift/pixels (since the user may, like me, have a shaky hand) even before you begin coding.

    You'd want to use a Swing Timer for that.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic