这听起来像是重复的,因为关于调整儿童Pane大小以适合Parent Pane的问题很多,但我几乎没有任何运气就尝试了所有方法。
我的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>
我想念什么?
最佳答案
我无法编译您的代码,因为其中存在错误。在第一个示例中,在prefWidth
和orientation
参数之间缺少空格,在第二个示例中,在orientation
参数之前有不必要的引号。修复它们之后,一切都会按预期进行。
这是固定代码:
<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>
请注意,您可以指定SplitPane的
prefWidth
,prefHeight
,layoutX
和layoutY
,但是由于锚点设置为0,并且它是AnchorPane
的唯一子项,因此它将始终占用所有可用空间,因此是多余的。关于java - 调整SplitPane的大小以适合AnchorPane父级,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38945441/