Issue
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?
Solution
Apply the following css:
Button:hover{
-fx-underline: true;
}
Answered By - c0der
Answer Checked By - David Goodson (JavaFixing Volunteer)