0

Is there a way to place an image as a background of a Stage instead of adding it first to an ImageView?

        ImageView splash = new ImageView(getClass().getResource("/splash.png").toExternalForm());
        VBox splashLayout = new VBox();
        splashLayout.getChildren().addAll(splash, progressText, loadProgress);
        Scene splashScene = new Scene(splashLayout);
        initStage.setScene(splashScene);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

1

For that you have to use CSS with your JavaFx,

here is a code for CSS

.root{
    -fx-background-image: url("your_image.jpg");
}

and add this css file to your scenes by,

scene.getStylesheets().add(getClass().getResource("myCss.css").toExternalForm());
Shreyas Dave
  • 3,815
  • 3
  • 28
  • 57