【问题标题】:FXML minHeight & minWidth attributs ignored?FXML minHeight 和 minWidth 属性被忽略了吗?
【发布时间】:2016-08-27 04:02:43
【问题描述】:

如何设置窗口的最小尺寸?我尝试设置 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>

【问题讨论】:

    标签: java javafx fxml window-resize minimum-size


    【解决方案1】:

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

    Parent root = FXMLLoader.load(getClass().getResource("/your/layout.fxml"));
    
    stage.setMinWidth(root.minWidth(-1));
    stage.setMinHeight(root.minHeight(-1));
    

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

    【讨论】:

      【解决方案2】:

      为此,您必须设置StageminHeightminWidth

      在您的 java 代码中的某处...:

      例子:

      ...
      yourStage.setMinHeight(480);
      yourStage.setMinWidth(640);
      ...
      

      【讨论】:

      • 为什么?请链接到文档。
      猜你喜欢
      • 1970-01-01
      • 2013-02-06
      • 2011-07-16
      • 2012-08-09
      • 1970-01-01
      • 2020-07-07
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多