• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SWT: how do differ between single and double click?

 
Serge Glaeser
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
i have a problem with the mouse selection in a tree. i can add a single and double click listener to the three with no problem. the problem i have is that when i double click an item it runs through both listener. Through the mouse down listener twice (first event with one click, second event with count = 2) and then again through the double click listener. However I want to execute different actions depending on the clicks, but since there seems to be always a single click involved this makes it kinda impossible. Is there a way to differ between the clicks, so that the mouse down (single click) listener only reacts when the user really clicked just once?

Thanks
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how would you know the first click from a 'series of clicks'? You cannot. You simply have to wait if further clicks happen. When there's only one click in a span of time it's a single click. When there're more than one click in that time span, it's a not-single-click. Are you sure you need both actions (click and double-click) in the way you described?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never worked on SWT, but in Swing you got a method called MouseEvent#getClickCount() which is used to identify double clicks. You might want to check for something similar in SWT.
 
David A. Smith
Greenhorn
Posts: 9
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like mentioned, you have to handle single *and* double clicks. In most applications, double-clicking on something is an extension of single-clicking on that same thing, so it usually ends up okay. Here's some code:



Then of course you need to install the handler...

 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dave,

thanks for the input, but I think you missed the "SWT" part. In Swing/AWT this is indeed the way to go.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I encoutered similar issue last time. Although, MouseEvent has count property, the SWT.MouseDown event is always called first before the SWT.MouseDoubleClick. So the workaround is to wait till the SWT.MouseDoubleClick has been fired, then check the flag which event was fired. The code is something like below.

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Mason Wardle

You cannot delete posts, but I can.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic