0

I have some issue with switch scenes at JavaFX. I have the primary stage that I set to him the first scene with background number 1:

image

then I switch to the new scene and I get this screen:

enter image description here

how can I resize my new CSS to cover the all screen?

I tried to set the background into my new scene but as you see that result above

css of second background:

.grass{
    -fx-background-image:url("/images/25474739-closeup-image-of-natural- 
green-grass-soccer-field.jpg");
    -fx-background-repeat:stretch,stretch;
    -fx-background-size:cover;
    -fx-background-position: center center;
}

css of first one:

  .root {
          -fx-background-image: url("/images/menu.jpg");
        -fx-background-size:cover;
        -fx-background-position: center center;
      }

the function that i change the scenes:

 public void switchMain(String string , AnchorPane container,String css) {
            try {
                FXMLLoader fxmlLoader = new FXMLLoader();
                AnchorPane root  = 
    fxmlLoader.load(getClass().getResource("GameScreen.fxml").openStream());
                container.getChildren().setAll(root);
                if(!css.equals("")) {
     myStage.getScene().getStylesheets().add(getClass().getResource
    ("MazeDisplyGra 
    ss.css").toExternalForm());
                }
            } catch (IOException e){
            }

I am not have any idea how to solve it. so please, if you get some good solution , share it with me : )

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
  • Please provide a [mcve] that demonstrates the problem. – kleopatra Jun 08 '19 at 10:44
  • Honestly i wouldnt do this in css, I would use constraints see this : https://stackoverflow.com/questions/36469958/javafx-screen-resolution-scaling/36472604#36472604 You just stretch the component over the whole container. – Tomas Bisciak Jun 08 '19 at 11:24

0 Answers0