0

我想通过鼠标右键单击切换按钮来运行一个阶段,

ToggleButton tb = new ToggleButton();

我应该使用什么 OnMouse 方法?

4

1 回答 1

1

试试这个 onPressed:

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

对于 onReleased:

tb.setOnMouseReleased(new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent mouseEvent) {
    if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) {
      System.out.println("hi");
    }
  }
});
于 2013-06-19T08:47:02.443 回答