我正在使用 JavaFX 和 SceneBuilder 创建一个场景。在其中一个选项卡中有一个SplitPane,当我将窗口放在最大尺寸并将其向上拖动以展开后一个视图时,它的行为并不像我想要的那样。 我希望ListView相应地扩展,但一旦达到最大高度,它就会停止。如何解决这个问题?
这是一个屏幕截图:您可以看到列表视图和分割窗格分隔符之间有一个很大的空间。
这里是xml的代码:
<TabPane prefHeight = "400.0"
prefWidth = "600.0"
tabClosingPolicy = "UNAVAILABLE"
AnchorPane.bottomAnchor = "0.0"
AnchorPane.leftAnchor = "0.0"
AnchorPane.rightAnchor = "0.0"
AnchorPane.topAnchor = "28.0">
<tabs>
<Tab text = "Clump">
<content>
<SplitPane dividerPositions = "0.22713864306784662"
orientation = "VERTICAL">
<items>
<VBox alignment = "CENTER_LEFT"
spacing = "10.0">
<padding>
<Insets bottom = "10.0"
left = "10.0"
right = "10.0"
top = "10.0" />
</padding>
<children>
<HBox alignment = "CENTER_LEFT"
prefHeight = "100.0"
prefWidth = "200.0"
spacing = "10.0">
<children>
<RadioButton fx:id = "radioClump"
mnemonicParsing = "false"
selected = "true"
text = "Ricerca per clump ID">
<toggleGroup>
<ToggleGroup fx:id = "clumpSearch" />
</toggleGroup>
</RadioButton>
<TextField fx:id = "textClumpId"
promptText = "Clump id" />
<Button fx:id = "searchClumpButton"
mnemonicParsing = "false"
text = "Cerca" />
</children>
</HBox>
<RadioButton fx:id = "radioStar"
mnemonicParsing = "false"
text = "Clump che possono ospitare una stella massiccia"
toggleGroup = "$clumpSearch" />
</children>
</VBox>
<VBox alignment = "BOTTOM_CENTER"
prefHeight = "100.0"
prefWidth = "200.0">
<children>
<ListView>
<padding>
<Insets bottom = "15.0"
left = "15.0"
right = "15.0"
top = "15.0" />
</padding>
</ListView>
<HBox alignment = "BOTTOM_RIGHT"
prefWidth = "600.0"
spacing = "5.0">
<children>
<Button mnemonicParsing = "false"
text = "<" />
<Button mnemonicParsing = "false"
text = ">" />
</children>
<padding>
<Insets top = "5.0" />
</padding>
</HBox>
</children>
</VBox>
</items>
</SplitPane>
</content>
</Tab>
[... OTHER TABS ...]
</tabs>
</TabPane>
答案 0 :(得分:2)
除非另有指示,否则VBox
将根据其preferredHeight
调整其子节点的大小。您可以通过在节点上设置静态VBox
属性vgrow
来覆盖此行为。在FXML中,语法为:
<ListView VBox.vgrow="ALWAYS">
<padding>
<Insets bottom = "15.0"
left = "15.0"
right = "15.0"
top = "15.0" />
</padding>
</ListView>