JavaFX: stage's minHeight considering titlebar's height

本秂侑毒 提交于 2019-12-08 04:28:30

问题


I'm currently building a small UI application for personal purpose and I ran into a problem. Here is some code:

public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("ui.fxml"));

    Scene scene = new Scene(root);

    stage.setTitle("My app");
    stage.setScene(scene);
    stage.setMinHeight(608.0);
    stage.setMinWidth(1080.0);

    stage.show();
}

And here's the FXML code assiociated with:

<GridPane gridLinesVisible="true" minHeight="608.0" minWidth="1080.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="my.package.MyClass">
    <rowConstraints>
        <RowConstraints minHeight="500.0" prefHeight="500.0" vgrow="ALWAYS" />
        <RowConstraints maxHeight="108.0" minHeight="108.0" prefHeight="108.0" vgrow="NEVER" />
    </rowConstraints>
</GridPane>

So, my problem is that, at launch, the GridPane will effectively have a height of 608px but is still resizable to a smaller height. Indeed, it will be resizable until the stage will be 608px, including the title bar's height...

The behaviour I would like to have is that my GridPane can't have a smaller height than 608.0.

Do you know any ways to do that? Many thanks in advance!


回答1:


As @James_D pointed out in a comment, I simply had to modify my code as follow:

public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("ui.fxml"));

    Scene scene = new Scene(root);

    stage.setTitle("My app");
    stage.setScene(scene);

    stage.show();

    stage.setMinHeight(stage.getHeight());
    stage.setMinWidth(stage.getWidth());
}


来源:https://stackoverflow.com/questions/43346248/javafx-stages-minheight-considering-titlebars-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!