javacssjavafx-8fxml

How to control the JavaFX Tooltip's delay?


I was playing around with JavaFX's Tooltip. I realized that for me personally the delay between hovering over something and the tooltip actually appearing is too long. A look in the API reveals:

Typically, the tooltip is "activated" when the mouse moves over a Control. There is usually some delay between when the Tooltip becomes "activated" and when it is actually shown. The details (such as the amount of delay, etc) is left to the Skin implementation.

After some further investigation, I was not able to find any possibility to control the delay. The JavaFX CSS Reference has no information about delay time and a runtime-evaluation of getCssMetaData() did not help either.

I know that there is a way to control the tooltips manually via onMouseEntered(...) and onMouseExited(...), but is there really no other way? Or am I missing an obvious solution?


Solution

  • In Java 9 and later, you can do

    Tooltip tooltip = new Tooltip("A tooltip");
    tooltip.setShowDelay(Duration.seconds(3));
    

    There is also a hideDelay property, for the delay between the tooltip appearing and it being hidden again. The default values are 1 second for the showDelay and 200 milliseconds for the hideDelay.