cssjavafxfxml

JavaFX background Setting


I am making a simple software to Reserve Stadium Seats. I have a main page wish is the Login Page. I have a simple design. With a transparent background just to give it a form. As you can see in the image below.enter image description here As you can see the code can bee seen behind the form. When i login i have a simple logout button that takes me again to the same fxml to load the form. but this time the background is no longer transparent: enter image description here. As you see here it is green. it is by default white but i was trying to make it transparent again. this is the code i tried to do:

public void logoutButton (ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
    Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    Scene scene = new Scene(root);
    root.setStyle("-fx-background-color: #20825170;");
    stage.setScene(scene);
}

even changing the style to transparent wont work i tried it. any help ?


Solution

  • You need to set the fill of the scene to transparent when a user logs out

    scene.setFill(Color.TRANSPARENT);
    

    Edit

    As @jewelsea stated in the comments, You don't have to set the scene's fill to TRANSPARENT every time if you don't change the scene, you can keep the same scene and only set the fill to transparent the first time (in the Application's start method will work)