Javafx 根据分辨率调整边框窗格的大小
我有一个边框窗格(也是VBox和矩形),我想根据屏幕大小调整大小。我在14英寸和21英寸显示器上使用我的应用程序。有没有办法根据屏幕大小调整组件的大小?我希望,我对您的理解是正确的:Javafx 根据分辨率调整边框窗格的大小,javafx,javafx-2,javafx-8,Javafx,Javafx 2,Javafx 8,我有一个边框窗格(也是VBox和矩形),我想根据屏幕大小调整大小。我在14英寸和21英寸显示器上使用我的应用程序。有没有办法根据屏幕大小调整组件的大小?我希望,我对您的理解是正确的: Screen screen = Screen.getPrimary(); Rectangle2D bounds = screen.getVisualBounds(); //let the window use the left half screen: stage.setX(bou
Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();
//let the window use the left half screen:
stage.setX(bounds.getMinX());
stage.setY(bounds.getMinY());
stage.setWidth(bounds.getWidth() / 2);
stage.setHeight(bounds.getHeight());
VBox vBox = new VBox();
vBox.setStyle("-fx-background-color: blue;");
Rectangle rect = new Rectangle();
rect.setStyle("-fx-fill: red;");
vBox.getChildren().add(rect);
//not necessary, because always max size (root element of the scene):
//vBox.minWidthProperty().bind(stage.widthProperty());
//vBox.minHeightProperty().bind(stage.heightProperty());
rect.widthProperty().bind(vBox.widthProperty());
rect.heightProperty().bind(vBox.heightProperty().divide(3));
stage.setScene(new Scene(vBox));
stage.show();
如果调整窗口大小,则元素将自动调整其自身大小。有没有办法使用父元素大小来实现此目的?通常使用父元素大小来完成。rect是vBox的子级,并且rect绑定到vBox大小。