简体   繁体   中英

Java double click excluding singleclick

Can anybody tell my how can I fix this...

@Override
public void mouseClicked(MouseEvent me) {
    super.mouseClicked(me);
        if (me.getClickCount() >= 2) {
            System.out.println("double click");
        }else{
            System.out.println("single click");
    }
}

When I doubleclick on my component in row wihout any time between clicking,it writes in console first " single click " and then " double click ". Thanks for answers.

You cannot avoid this the way you are doing it right now.

When you first click, the mouseClicked event is called immediatly and doesn't wait for the second click to execute. That is why "single click" is displayed.

A way of doing it would be using a timer . Start the timer after the click, and if there is no 2nd click before 1 sec (or any time you chose) then consider as single click but if there is a second one consider it as a double click. That solution demands a little bit of thinking about how to implement, but not impossible I guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM