*
The moose likes Swing / AWT / SWT and the fly likes trapping double clicks using getClickCount of MouseEvent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "trapping double clicks using getClickCount of MouseEvent" Watch "trapping double clicks using getClickCount of MouseEvent" New topic
Author

trapping double clicks using getClickCount of MouseEvent

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
I'd like to know if there is a better way to trap double clicks then using getClickCount() in MouseEvent?
Using getClickCount is not reliable in my tests. Most of the time when I trap double clicks it is not working 100% of the time. One has to click slowly in order for it to be somewhat reliable.
Has anyone seen this problem?
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
easy to get around. Use a
Date lastClick;
variable. Check lastClick.getTime() in the mouseClicked method (or mousePressed).
If it is within a certain number of milisecs of the current time, its a double click and you kick off your event.
If it is out of the time range you specify it sets the lastClick to the current time and exits waiting for the next click.
Hope this helps,
Chris
[ October 07, 2002: Message edited by: Chris Shepherd ]
 
Don't get me started about those stupid light bulbs.
 
subject: trapping double clicks using getClickCount of MouseEvent
 
Similar Threads
mouse event
SWT: how do differ between single and double click?
Java Multi-Modes Button
Double Click anyone?
how a double-click is been recognized?