• Post Reply Bookmark Topic Watch Topic
  • New Topic

Double Click anyone?  RSS feed

 
Jason Stortz
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone! I am trying to figure out a way to find out if someone double clicks inside of a JTextArea.
I know how to do this with a mouse listener and catch the event that occurs when they click once, or to listen for the mouse down event.
Is there an elegant and/or easy way to figure out a double click? Please point me in the right direction. Thanks.
Jason
SCJP
 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can use the method, MouseEvent.getClickCount() to find the number of clicks associated with that MouseEvent.
Ashwin.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about the getClickcount() method in the mouseEvent? I think that should do it for you. I'm not sure what the time is for considering all the clicks to be part of the same event (I assume it would be system dependent).
you could just test:
if (e.getClickCount() == 2) {
// do something
}
hope that helps you out

Dave
 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you double click on a component, you fire two events,
the first with one click, and the second with the click count on 2
So you should only handle the event with the click count on 2
if (e.getClickCount() == 2) {
//handle the event
}else{
// do not.
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!