Javafx 2单击并双击 [英] Javafx 2 click and double click

查看:1248
本文介绍了Javafx 2单击并双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以检测到JavaFX 2中的双击?以及如何?

I would like to know if it was possible to detect the double-click in JavaFX 2 ? and how ?

我想在点击和双击之间进行不同的活动。

I would like to make different event between a click and a double click.

/ p>

Thanks

推荐答案

是的,您可以检测单次,双重甚至多次点击:

Yes you can detect single, double even multiple clicks:

myNode.setOnMouseClicked(new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent mouseEvent) {
        if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){
            if(mouseEvent.getClickCount() == 2){
                System.out.println("Double clicked");
            }
        }
    }
});

MouseButton.PRIMARY 左(通常)鼠标按钮触发事件。阅读 getClickCount()的api可以得出结论,可能有单次点击或双次点击之外的其他点击计数。但是,我发现很难区分单击和双击事件。因为双击的第一次点击计数也会上升一个事件。

MouseButton.PRIMARY is used to determine if the left (commonly) mouse button is triggered the event. Read the api of getClickCount() to conclude that there maybe multiple click counts other than single or double. However I find it hard to distinguish between single and double click events. Because the first click count of the double click will rise a single event as well.

这篇关于Javafx 2单击并双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆