Java 调整拆分窗格的大小以适合AnchorPane父级

Java 调整拆分窗格的大小以适合AnchorPane父级,java,javafx,fxml,scenebuilder,Java,Javafx,Fxml,Scenebuilder,这听起来像是重复的,因为有很多关于调整子窗格大小以适应父窗格的问题,但我几乎什么都试过了,没有任何运气 我的SplitPane位于AnchorPane内,这是我的原始代码: <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="792.0" prefWidth="1055.0" xmlns="http:/

这听起来像是重复的,因为有很多关于调整子窗格大小以适应父窗格的问题,但我几乎什么都试过了,没有任何运气

我的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>
在子窗格中。我尝试过这一点,但运气不佳:这就是我的代码现在的样子:

<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,并且它是
锚定盘的唯一子级,因此它将始终占用所有可用空间,因此是多余的。

我找到了答案!我在搜索同样的东西,但我的设置有点不同。我使用了一个外部滚动窗格,其中有一个锚形窗格,还有一个拆分窗格,还有一个锚形窗格,它可以保持较小的尺寸,阻止拆分窗格调整大小。我所做的修复是选择滚动窗格并将fit to width和fit to height设置为true。还有一些适合母版。

尝试移除内部锚定窗格的预高、预宽。
<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>