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