Javafx 2 click and double click

前端 未结 9 1454
盖世英雄少女心
盖世英雄少女心 2020-12-01 06:00

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.

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 06:35

    Adhering to Java SE 8 lambda expressions would look something like this:

    node.setOnMouseClicked(event -> {
        if(event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2) {
            handleSomeAction();
        }
    });
    

    Once you get used to lambda expressions - they end up being more understandable than the original class instantiation and overriding (x) method. -In my opinion-

提交回复
热议问题