【发布时间】:2016-08-14 18:42:08
【问题描述】:
这听起来像是重复,因为有很多关于调整子窗格大小以适应父窗格的问题,但我几乎尝试了所有方法,但没有任何运气。
我的 SplitPane 位于 AnchorPane 内,这是我的原始代码:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="792.0" prefWidth="1055.0"
xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.judeochalifu.stock_manager.controller.NewSupplierController">
<children>
<SplitPane fx:id="splitPlane" dividerPositions="0.5" layoutX="371.0" layoutY="229.0" prefHeight="792.0" prefWidth="1055.0"orientation="VERTICAL" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
</items>
</SplitPane>
</children>
</AnchorPane>
这是没有调整大小的输出:
当我拖动窗口以增加宽度或高度时,这是我得到的:
SplitPane 期望的结果是随着窗口的扩展而扩展,即根据 Anchorpane 的宽度和高度调整大小。
环顾四周,我发现 OP 正在尝试类似的这两个问题:
JavaFX: FXML: How to make the child to extend its size to fit the parent pane?
JavaFX Panel inside Panel autoresizing
答案建议只使用属性:
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
在子窗格内。我试过这个没有运气:这就是我的代码现在的样子:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="792.0" prefWidth="1055.0"
xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.judeochalifu.stock_manager.controller.NewSupplierController">
<children>
<SplitPane fx:id="splitPlane" dividerPositions="0.5" "orientation="VERTICAL"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0"
prefWidth="160.0" />
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0"
prefWidth="160.0" />
</items>
</SplitPane>
</children>
</AnchorPane>
我错过了什么?
【问题讨论】:
-
尝试删除内部锚窗格的 prefHeight、prefWidth。
标签: java javafx fxml scenebuilder