Thank you for your quick response. Maybe, i didn't make the problem clear.

I mean the mouse double click event will trigger both mouse single click
processing logic and double click processing logic.

I think one mouse double click event makes the mouseClick method called
twice, with count=1 and count=2 respectively. So using if-else to check
count and does corresponding processing in the mouseClick method doesn't
work.
For example, i changed the mouseClick method as below:

@Override
public boolean mouseClick(Component component, Button button, int x, int y,
int count) {
if (count == 1) {
  System.out.println("Single Click");
    return true;
} else if (count == 2) {
  System.out.println("Double Click");
    return true;
}
return false;
}

One "Double Click" makes the app output

Single Click
Double Click

Actually, i think one N-click event makes the mouseClick method called for N
times, with count = 1,2,...,N-1,N respectively. So if I changed the
mouseClick method as below and performs a "triple click",

@Override
public boolean mouseClick(Component component, Button button, int x, int y,
int count) {
if (count == 1) {
  System.out.println("Single Click");
    return true;
} else if (count == 2) {
  System.out.println("Double Click");
    return true;
} else if (count == 3) {
                System.out.println("Triple Click");
    return true;
        }
return false;
}

The app will output:

Single Click
Double Click
Triple Click

I hope i make the problem clear this time :)

Any suggestions? Thanks a lot!

On Thu, May 5, 2011 at 3:36 PM, Chris Bartlett <[email protected]>wrote:

>  > So how to distinguish mouse single click and mouse double click? Thanks
> a lot!
> You should just be able to check the value of 'count' and only execute your
> double click code when there have been 2 mouse clicks.
> You might also check which mouse button the clicks came from.
>
> tableView.getComponentMouseButtonListeners().add(new
> ComponentMouseButtonListener() {
>
> @Override
> public boolean mouseClick(Component component, Button button, int x, int y,
> int count) {
>   if (count == 1) {
>   // Single click
>    return true;
>  } else if (count == 2) {
>   // Double click
>    return true;
> }
> System.out.println(count);
> return false;
>  }
>  });
>
>
>
> On 5 May 2011 14:08, Le Zhou <[email protected]> wrote:
>
>> Hi all,
>>
>> I added one ComponentMouseButtonListener instance to one TableView
>> instance, and overrided the mouseClick method
>> of ComponentMouseButtonListener class.
>> When i performed  one double click on the TableView, the mouseClick method
>> was called twice. Below are snippet of the experiment code:
>>
>> tableView.getComponentMouseButtonListeners().add(new
>> ComponentMouseButtonListener() {
>>
>> @Override
>> public boolean mouseClick(Component component, Button button, int x, int
>> y, int count) {
>>  System.out.println(count);
>> return false;
>> }
>>  });
>>
>> When i performed one double click on the tableView, output is like below:
>>
>> 1
>> 2
>>
>> I was kinda confused, because i thought the output should be "2".
>> I thought the count argument in mouseClick method is used to distinguish
>> mouse single click and mouse double click events.
>> But as shown in the output, it seems that the mouseClick method is called
>> twice in one mouse double click event: count is 1 in the 1st call and count
>> is 2 in the 2nd call.
>>
>> So how to distinguish mouse single click and mouse double click? Thanks a
>> lot!
>>
>>
>>
>

Reply via email to