LuminousNutria
LuminousNutria

Reputation: 2001

Button underline text on hover

I am working with JavaFX, and I have a Scene object I created in SceneBuilder with a bunch of Button objects. I want the text of each of these Button objects to be underlined when the mouse cursor enters their area in the window, and to remove the underlining when the cursor leaves.

I know I can just type:

public class Controller {

    @FXML
    private Button exitButton;

    public void exitButtonMouseEntered() {

       this.exitButton.setUnderline(true);
    }

    public void exitButtonMouseLeft() {

       this.exitButton.setUnderline(false);
    }

}

However, doing this for each Button object is time-consuming, and it seems like there must be an easier way to force all the Button objects to have the same behavior given the same conditions.

How can I make a controller method that will affect all the Buttons in the Scene?

Upvotes: 1

Views: 1707

Answers (1)

c0der
c0der

Reputation: 18792

Apply the following css:

Button:hover{
    -fx-underline: true;
}

enter image description here

Upvotes: 4

Related Questions