Search code examples
javajavafxdraggabledouble-clickscene

How to implement zoom on double Click in javafx?


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.


Solution

  • 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.