-1

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 ?

  • 3
    [mcve] please .. – kleopatra Jan 23 '22 at 15:21
  • See: [how to make transparent scene and stage in javafx?](https://stackoverflow.com/questions/34033119/how-to-make-transparent-scene-and-stage-in-javafx) – jewelsea Jan 23 '22 at 18:49
  • 2
    You don't need to set a new scene, you can reuse the existing one, `stage.getScene().setRoot(root);`. Presumably the original scene already had it's fill set to transparent or wouldn't be transparent. Also, you can set a stylesheet on the scene for a transparent background (like the answer to the question I linked): `.root { -fx-background-color: transparent; }`. – jewelsea Jan 23 '22 at 18:55

1 Answers1

1

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)

SDIDSA
  • 894
  • 10
  • 19