Javafx : Activate a tooltip with a button

后端 未结 3 1173
慢半拍i
慢半拍i 2021-01-12 08:37

I\'m using JavaFx for a little app and a want to display a tooltip on a textArea when the user is clicking on a \"help\" button.

No problem for linking a tootltip to

3条回答
  •  囚心锁ツ
    2021-01-12 09:20

    The following show a tooltip over control.
    If controlhas a Tooltip assigned to, this tooltip is not chnaged.

    public static void showOneTimeTooltip(Control control, String tooltipText) {
    
        Point2D p = control.localToScreen(5 , 5);
    
        final Tooltip customTooltip = new Tooltip(tooltipText);
        customTooltip.setAutoHide(false);
        customTooltip.show(control,p.getX(),p.getY());
    
        PauseTransition pt = new PauseTransition(Duration.millis(2000));
        pt.setOnFinished(e->{
            customTooltip.hide();
        });
        pt.play();
    }
    

提交回复
热议问题