How to set a tooltip on a JavaFX Button?

前端 未结 3 626
青春惊慌失措
青春惊慌失措 2021-01-07 21:47

How can I set a title or a text that appears above a button when I hover it with the mouse?

3条回答
  •  猫巷女王i
    2021-01-07 22:17

    The Tooltip class is what you are looking for.

    Example for a simple Tooltip

    Button button = new Button("Hover Me");
    button.setTooltip(new Tooltip("Tooltip for Button"));
    

    You can also customize your Tooltips: CSS Reference for Tooltip.

    Example for a styled Tooltip

    Button button = new Button();
    button.setText("Hover Me!");
    Tooltip tt = new Tooltip();
    tt.setText("Text on Hover");
    tt.setStyle("-fx-font: normal bold 4 Langdon; "
        + "-fx-base: #AE3522; "
        + "-fx-text-fill: orange;");
    
    button.setTooltip(tt);
    

提交回复
热议问题