I have a SplitPane and within it two items which are VBox and ScrollPane. In the VBox I have some TitledPane children that can be collapsed and therefore minimize the VBox height, or this is what I thought will happen. But the issue is that only the inner elements of the VBox are being shrunk inside it and the actual VBox child height stays the same.
I want the VBox to dynamically change in height and the divider of the SplitPane to automatically fill the gap of the shrunk VBox so that the ScrollPane will fill that gap.
<SplitPane fx:id="infoSplitPane" orientation="VERTICAL" dividerPositions="0.35">
<items>
<VBox fx:id="campaignInfoVBox" spacing="10" VBox.vgrow="ALWAYS">
<children>
<Label text="Campaign Information" style="-fx-font-size: 120%" />
<SplitPane fx:id="campaignInfoSplitPane" orientation="VERTICAL">
<items>
<TitledPane fx:id="campaignTestsFlow" text="Campaign Tests Flow">
<TableView fx:id="testCasesTableView" minHeight="52" maxHeight="Infinity" VBox.vgrow="ALWAYS">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</TitledPane>
<TitledPane fx:id="campaignActionsInfo" text="Campaign Actions Information">
<SplitPane fx:id="campaignTablesSplitPane" orientation="VERTICAL" VBox.vgrow="ALWAYS">
<items>
<RunnerActionsTreeTableView fx:id="campaignSetupTable" name="Campaign Setup" VBox.vgrow="SOMETIMES" />
<RunnerActionsTreeTableView fx:id="campaignTearDownTable" name="Campaign Tear Down" VBox.vgrow="ALWAYS" />
</items>
</SplitPane>
</TitledPane>
</items>
</SplitPane>
</children>
</VBox>
<ScrollPane fx:id="testInfoScrollPane" fitToWidth="true" VBox.vgrow="ALWAYS">
<content>
<VBox spacing="0" VBox.vgrow="ALWAYS">
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" vgap="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="0.0">
<children>
<VBox fx:id="titledPaneVbox" GridPane.rowIndex="13" GridPane.columnSpan="2">
<TitledPane fx:id="variablesTitlePane" maxHeight="1.7976931348623157E308" text="Variables Information" VBox.vgrow="ALWAYS" >
<content>
<TableView fx:id="variablesTable" maxHeight="Infinity" maxWidth="Infinity" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS" />
</content>
</TitledPane>
<TitledPane fx:id="eventsTitlePane" maxHeight="1.7976931348623157E308" text="Events Information" VBox.vgrow="ALWAYS" GridPane.columnSpan="2">
<content>
<TableView fx:id="eventsTable" maxHeight="Infinity" maxWidth="Infinity" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS"/>
</content>
</TitledPane>
</VBox>
<Button fx:id="testCaseDirButton" text="Logs Folder" maxWidth="Infinity" GridPane.rowIndex="14" GridPane.hgrow="ALWAYS" GridPane.columnSpan="2" />
</children>
</GridPane>
</VBox>
</content>
</ScrollPane>
</items>
</SplitPane>
So basically what I need it the testInfoScrollPane to adjust itself to campaignInfoVBox bottom margin when it is being shrunk automatically when its TitledPane children are collapsing.
I believe you need to set the
maxHeightattribute ofVBoxto the prefHeight of its contents. That way, theVBoxcan never grow beyond the size of its contents.You can try the below code:
If in java code:
If in FXML code:
Below is a quick demo that demonstrates the fix:
UPDATE: When applied the attribute in the provided FXML, this is how it works.