【问题标题】:Resizing SplitPane to fit AnchorPane parent调整 SplitPane 的大小以适合 AnchorPane 父级
【发布时间】: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


【解决方案1】:

我无法编译您的代码,因为其中有错误。第一个示例中的prefWidthorientation 参数之间缺少空格,第二个示例中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 的 prefWidthprefHeightlayoutXlayoutY,但由于锚点设置为 0,并且它是 AnchorPane 的唯一子项,因此它将始终占用所有可用空间,因此它是多余的。

【讨论】:

    【解决方案2】:

    我找到了答案!我正在寻找同样的东西,但我的设置有点不同。我使用了一个外部滚动窗格,其中一个锚窗格,一个拆分窗格,以及一个会保持较小并阻碍拆分窗格调整大小的锚窗格。我所做的修复它是选择 SCROLLpane 并将适合宽度和适合高度设置为 true。还有一些适合父母的。

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      相关资源
      最近更新 更多