gpt4 book ai didi

java - 为辅助鼠标按钮添加鼠标事件 Javafx

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:36 26 4
gpt4 key购买 nike

所以我有这个锚定 Pane ,我想在其中为辅助鼠标键添加鼠标监听器我尝试了以下但我不断收到错误有人知道问题出在哪里吗?

   mainDisplayPanel.addEventHandler(MouseButton.SECONDARY, new EventHandler<MouseButton>() {

@Override
public void handle(MouseButton event) {
System.out.Println("Works");

}
});

郑重声明,我也试过这个:

            mainDisplayPanel.addEventHandler(MouseButton.SECONDARY, new EventHandler<MouseEvent>() {

@Override
public void handle(MouseEvent event) {
System.out.println("WOrks");
}
});

堆栈跟踪:

Bound mismatch: The generic method addEventHandler(EventType, EventHandler) of type Node is not applicable for the arguments (MouseButton, new EventHandler(){}). The inferred type MouseButton&Event is not a valid substitute for the bounded parameter

还有一个:

Bound mismatch: The type MouseButton is not a valid substitute for the bounded parameter of the type EventHandler

最佳答案

没有基于MouseButton.SECONDARYEventType。您需要检查 MouseEvent 本身:

mainDisplayPanel.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {

@Override
public void handle(MouseEvent event) {
if (event.getButton() == MouseButton.SECONDARY) {
System.out.println("Works");
}
}
});

关于java - 为辅助鼠标按钮添加鼠标事件 Javafx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14008181/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com