Search code examples
javafxtooltipmousehover

Detect mouse hovering over a Tooltip


In relation to this question I would like to know if it is possible to trigger an event if the mouse is hovering over a Tooltip. I know this method node.setOnMouseEntered() but this applies only to instances of Node (Tooltip does not extend Node).


Solution

  • Get the scene from the Tooltip and register the event handlers there:

    Tooltip tooltip = new Tooltip("Something");
    Scene tooltipScene = tooltip.getScene();
    
    tooltipScene.setOnMouseEntered(evt -> {
        System.out.println("enter");
    });
    tooltipScene.setOnMouseExited(evt -> {
        System.out.println("exit");
    });