简体   繁体   English

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

[英]Adding mouse event for secondary mouse button Javafx

so i have this anchorpane where i wish to add a mouse listner for the Secondary mouse key ive tried the following but i keep getting an error anyone know what the problem is? 所以我有这个锚板,我希望为辅助鼠标键添加鼠标列表器我尝试了以下但我不断得到一个错误,任何人都知道问题是什么?

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

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

                    }
                });

for the record i have also tried this: 为了记录,我也试过这个:

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

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

Stack trace: 堆栈跟踪:

Bound mismatch: The generic method addEventHandler(EventType, EventHandler) of type Node is not applicable for the arguments (MouseButton, new EventHandler(){}). 绑定不匹配:Node类型的泛型方法addEventHandler(EventType,EventHandler)不适用于参数(MouseButton,new EventHandler(){})。 The inferred type MouseButton&Event is not a valid substitute for the bounded parameter 推断类型MouseButton&Event不是有界参数的有效替代

And the other: 和另外一个:

Bound mismatch: The type MouseButton is not a valid substitute for the bounded parameter of the type EventHandler 绑定不匹配:MouseButton类型不是EventHandler类型的有界参数的有效替代

There is no EventType based on MouseButton.SECONDARY . 没有基于MouseButton.SECONDARY EventType You need to check the MouseEvent itself: 您需要检查MouseEvent本身:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM