Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 278
Turing85 Avatar asked Nov 10 '14 22:11

Turing85


1 Answers

I use the next hack for this via Reflection

public static void hackTooltipStartTiming(Tooltip tooltip) {     try {         Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR");         fieldBehavior.setAccessible(true);         Object objBehavior = fieldBehavior.get(tooltip);          Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer");         fieldTimer.setAccessible(true);         Timeline objTimer = (Timeline) fieldTimer.get(objBehavior);          objTimer.getKeyFrames().clear();         objTimer.getKeyFrames().add(new KeyFrame(new Duration(250)));     } catch (Exception e) {         e.printStackTrace();     } } 
like image 162
Igor Luzhanov Avatar answered Oct 13 '22 11:10

Igor Luzhanov