給某個控件設置鼠標點擊監聽器,三個條件分別判斷為單擊,右擊還是雙擊
- 單擊判斷 event.getButton()==MouseButton.PRIMARY
- 右擊判斷 event.getButton()==MouseButton.SECONDARY
- 雙擊判斷 event.getClickCount() == 2
例子:
control.setOnMouseClicked(event -> { MouseButton button = event.getButton(); //單擊操作 if (button == MouseButton.PRIMARY) { } //右鍵點擊 if (button == MouseButton.SECONDARY) { } //雙擊操作 if (event.getClickCount() == 2) { } }