我想通过鼠标右键单击切换按钮来运行一个阶段,
ToggleButton tb = new ToggleButton();
我应该使用什么 OnMouse 方法?
我想通过鼠标右键单击切换按钮来运行一个阶段,
ToggleButton tb = new ToggleButton();
我应该使用什么 OnMouse 方法?
试试这个 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");
}
}
});