1

How to implement dbl Click on javafx?

I have a scene(with many components) and I want to make it drag able as well as double clickable to zoom in. How can I achieve this dynamic behavior? I have used the given solution but they are not helpful When I drag two time then the the double click event get triggers. That I don't want.

A bit of sample code will be appreciated.

P. Pandey
  • 108
  • 11

2 Answers2

0

You can add a wait time, before the drag of the single click gets initiated.

  • Boolean that specifies if double click happened

  • On drag / drop: set boolean to false

  • On drag / drop: wait specified milliseconds before checking the boolean
  • On drag / drop: check if boolean false -> proceed

  • Double click: set boolean true

That should work?

Edit: On drag / drop: wait specified milliseconds before checking the boolean - That is basically the delay that you define as a double click still being a double click and not two separate clicks

Edit2: Mile's comment to the question seems a better way to go in this case.

JohnRW
  • 748
  • 7
  • 22
  • your answer is near to achieve what I want but not completely. the best part is to detect and manage mouse release event based on dragged, clicked and time span between two clicks if its not dragged. – P. Pandey Feb 11 '16 at 13:30
0

Try this code for double click.

  myPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){
                if(mouseEvent.getClickCount() == 2){
                    //Write zooming logic here.
                }
            }
        }
    });

I hope it will help you.

Venkat Prasanna
  • 692
  • 4
  • 16