javafx 鼠标事件

给某个控件设置鼠标点击监听器,三个条件分别判断为单击,右击还是双击

  • 单击判断 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) { }
}
05-11 18:16