Java FX mouse events

To set up a control mouse click listener, three conditions are judged to click, right-click or double-click

  • Click judgment event.getButton () == MouseButton.PRIMARY
  • Right-click the determination event.getButton () == MouseButton.SECONDARY
  • Double-determination event.getClickCount () == 2

example:

control.setOnMouseClicked (Event -> { 

        MouseButton Button = event.getButton ();
         // click operation 
        IF (Button == MouseButton.PRIMARY) { 
           
        } 

        // Right-click 
        IF (Button == MouseButton.SECONDARY) { 
            
        } 
        
        // double tap operation 
        IF (event.getClickCount () == 2 ) { 
           
        } 
}

Guess you like

Origin www.cnblogs.com/steveshao/p/12134306.html