JavaFX在开始剪切之前获得窗格的最小宽度/高度/大小

时间:2017-11-01 11:12:07

标签: javafx javafx-8 javafx-2

F为了简单起见,最好向您展示问题并进行描述 1 2 3

我计划在窗格(此示例中为groupPane)开始剪裁之前将窗口的最小宽度设置为可能的最小尺寸

我怎样才能预先计算出这个宽度。

fxml部分:

enter image description here

目前的计算方法:

public void setupMinStageSizeInStandardMode(Stage primaryStage, Scene scene)
{
    // the thickness of the border of the window
    ObjectBinding<Insets> insets = Bindings.createObjectBinding(() ->
                    new Insets(scene.getY(),
                            primaryStage.getWidth()-scene.getWidth() - scene.getX(),
                            primaryStage.getHeight()-scene.getHeight() - scene.getY(),
                            scene.getX()),
            scene.xProperty(),
            scene.yProperty(),
            scene.widthProperty(),
            scene.heightProperty(),
            primaryStage.widthProperty(),
            primaryStage.heightProperty()
    );

    //i am trying to get the grid to the smallest size here
    controlsGrid.setMaxWidth(0);
    controlsGrid.setPrefWidth(0);

    // then i am trying to calculate the wanted size
    double minStageWidth = controlsGrid.getWidth() +insets.get().getLeft() + insets.get().getRight();
    double minStageHeight = controlsGrid.getHeight() +insets.get().getTop() + insets.get().getBottom();

    System.out.println(minStageWidth);
    System.out.println(minStageHeight);

    //then return the grid to it's intended size
    controlsGrid.setMaxWidth(Region.USE_PREF_SIZE);
    controlsGrid.setPrefWidth(Region.USE_PREF_SIZE);

    primaryStage.setMinHeight(minStageHeight);
    primaryStage.setMinWidth(minStageWidth);
}

请帮忙。我正在失眠......

0 个答案:

没有答案
相关问题