【发布时间】:2018-09-17 17:20:34
【问题描述】:
如何在增加或减少窗口框架时将背景图像设置为窗口大小?现在图像的设置大小为 300,300,因此当增加窗口时,大小保持不变。 这是我的代码的 sn-p:
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();
【问题讨论】:
标签: java image user-interface javafx background-image