0

How would I be able to set the background image to the size of the window when increasing or decreasing the window frame? Right now the image is a set size of 300,300 so when increasing the window the size stays the same. Here's a snippet of my code:

    grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, 
    loginButton);

    grid.setMinSize(300,300);
    grid.setMaxSize(300,300);
    StackPane root = new StackPane(grid);
    NumberBinding maxScale = Bindings.min(root.widthProperty().divide(300), 
    root.heightProperty().divide(300));
    grid.scaleXProperty().bind(maxScale);
    grid.scaleYProperty().bind(maxScale);

    BackgroundImage myBI= new BackgroundImage(new Image("image.jpg", 300, 300, 
    false, true),
    BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, 
    BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT);
    //then you set to your node
    grid.setBackground(new Background(myBI));

    Scene scene = new Scene(root, 300,300);
    window.setScene(scene);
    window.show();
user9613585
  • 31
  • 2
  • 5
  • https://stackoverflow.com/questions/23515172/set-background-image-the-same-size-as-the-window-screen-in-java-app – SedJ601 Apr 08 '18 at 04:45

1 Answers1

0

You can try to instantiate a BackgroundSize object according to documentation and set the cover value to true. Then instead of using BackGroundSize.DEFAULT, use the BackGroundSize object you created.

Emre Dalkiran
  • 401
  • 3
  • 9