JavaFX:舞台的minHeight考虑标题栏的高度 [英] JavaFX: stage's minHeight considering titlebar's height

查看:444
本文介绍了JavaFX:舞台的minHeight考虑标题栏的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为个人目的构建一个小型UI应用程序,但我遇到了一个问题。下面是一些代码:

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

以下是与之相关的FXML代码:

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>

所以,我的问题是,在启动时,GridPane的有效高度 608px 但仍可调整到较小的高度。事实上,它将可以重新调整,直到阶段 608px ,包括标题栏的高度......

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...

我想要的行为是我的GridPane的高度不能小于 608.0

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!

推荐答案

正如@James_D在评论中指出的那样,我只需要修改我的代码如下所示:

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

这篇关于JavaFX:舞台的minHeight考虑标题栏的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆