Javafx 2 click and double click

前端 未结 9 1453
盖世英雄少女心
盖世英雄少女心 2020-12-01 06:00

I would like to know if it was possible to detect the double-click in JavaFX 2 ? and how ?

I would like to make different event between a click and a double click.

9条回答
  •  失恋的感觉
    2020-12-01 06:41

    The response by P. Pandey is the simplest approach which actually distinguishes between single and double click, but it did not work for me. For one, the function "currentTimeMillis" already returns milliseconds, so dividing it by 1000 does not seem to be necessary. The version below worked for me in a more consistent fashion.

     @Override
     public void handle(MouseEvent t) {
    
            long diff = 0;
    
            currentTime=System.currentTimeMillis();
    
            if(lastTime!=0 && currentTime!=0){
                diff=currentTime-lastTime;
    
                if( diff<=215)
                    isdblClicked=true;
                else
                    isdblClicked=false;
            }
    
            lastTime=currentTime;
    
            System.out.println("IsDblClicked()"+isdblClicked); 
    
           //use the isdblClicked flag...   
    }
    

提交回复
热议问题