右键单击切换按钮

时间:2013-06-19 08:14:07

标签: javafx-2 togglebutton

我想通过鼠标右键单击切换按钮

来运行舞台
ToggleButton tb = new ToggleButton();

我应该使用什么OnMouse方法?

1 个答案:

答案 0 :(得分:1)

尝试使用onPressed:

tb.setOnMousePressed(new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent mouseEvent) {
    if (mouseEvent.isSecondaryButtonDown()){
      System.out.println("hi");
    }
  }
});

for onReleased:

tb.setOnMouseReleased(new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent mouseEvent) {
    if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) {
      System.out.println("hi");
    }
  }
});