Java : ignore single click on double click?

后端 未结 4 1420
名媛妹妹
名媛妹妹 2020-12-29 09:00

can anyone think of a good way to ignore the single click that comes with a double-click in Java ?

I\'m looking to have different behaviors for each such that:

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 09:27

    Have you tried implementing the MouseListener interface already?

    I think MouseEvent has a click count method ( or property ) to know that.

    I bet you have gone through that already, so what is the problem you're facing there?

    Probably what you can do is to code the time interval elapsed between a single and a double click with a thread or something.

    So a single click will only be valid if another click is not issued in let's say 300 ms. ( something configurable )

    The idea is:

    public void listen for the single click() 
        if (  in x time there has not been another click  ) 
        then 
            we have a single click
            proceed with your single click handling
        else 
            we have a double click
           proceed with your double click handling
    

    Or something like that.

提交回复
热议问题