根据分辨率调整BorderPane的大小

时间:2014-10-21 20:13:42

标签: javafx javafx-2 javafx-8

我有一个BorderPane(也是VBox和Rectangle),我想根据屏幕大小调整大小。我在14“和21”显示器上使用我的应用程序。有没有办法根据屏幕尺寸调整组件大小?

1 个答案:

答案 0 :(得分:1)

我希望,我理解你:

    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();

如果您调整窗口大小,则Elements会自动调整它们的大小。

相关问题