Wednesday, January 25, 2017

JavaFX WebView: Handling mouse click events with Java ScheduleFuture

Recently, while working on client application, we need to handle mouse click events on JavaFX WebView component, set different handlers for double click and single click events triggered on hyperlinks displayed in the webpage rendered.
We have tried different ways to do this, but we have got it achieved through Java ScheduleFuture and ScheduledThreadPoolExecutor


As shown in the code between line numbers 48-55, we assumed the delay between two mouse clicks(double click) is with in 400 milliseconds(It may be even lesser, around 250 milliseconds), scheduled a future task to be executed after 400 milliseconds, but with in this time limit, if there is any other click we cancel the task that was scheduled before and consider that as double click.