• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Double Click anyone?

 
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
 
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.
 
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
 
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!