6

如何设置窗口的最小尺寸?我尝试设置该minHeight minWidth值,但我仍然可以使用鼠标在此值下调整窗口的大小。

这是我的 FXML 根窗格:

<BorderPane fx:id="borderPane"
        minHeight="200" minWidth="400" prefHeight="600" prefWidth="800"
        xmlns="http://javafx.com/javafx/null"
        xmlns:fx="http://javafx.com/fxml/1"
        fx:controller="simulation.Simulation_Controller">
</BorderPane>
4

2 回答 2

4

为此,您必须设置minHeightminWidthStage.

在你的java代码中的某个地方......:

例子:

...
yourStage.setMinHeight(480);
yourStage.setMinWidth(640);
...
于 2016-05-02T12:32:14.227 回答
2

这是一个简单有效的解决方案:

Parent root = FXMLLoader.load(getClass().getResource("/your/layout.fxml"));

stage.setMinWidth(root.minWidth(-1));
stage.setMinHeight(root.minHeight(-1));

这会将舞台的最小大小设置为 FXML 文件的顶级元素中定义的值,如果未定义,则设置为 0。

于 2017-11-06T09:53:19.907 回答