Javafx 2 如何将图像放置到舞台作为背景?
有没有一种方法可以将图像作为舞台的背景,而不是先将其添加到ImageView中Javafx 2 如何将图像放置到舞台作为背景?,javafx-2,javafx,Javafx 2,Javafx,有没有一种方法可以将图像作为舞台的背景,而不是先将其添加到ImageView中 ImageView splash = new ImageView(getClass().getResource("/splash.png").toExternalForm()); VBox splashLayout = new VBox(); splashLayout.getChildren().addAll(splash, progressText, loadProg
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);
为此,您必须在JavaFx中使用CSS 下面是CSS的代码
.root{
-fx-background-image: url("your_image.jpg");
}
并通过以下方式将此css文件添加到场景中:
scene.getStylesheets().add(getClass().getResource("myCss.css").toExternalForm());