Reputation: 27237
This might sound like a duplicate since there are tons of questions regarding resizing a child Pane to fit Parent Pane but I have tried almost everything without any luck.
My SplitPane is located inside an AnchorPane and this is my original code:
<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>
This is the output without resizing:
When I drag the window to increase width or height, this is what I get:
The desired result is for the SplitPane to expend as the window expands, that is to resize according to the width and height of the Anchorpane.
Looking around I found these two questions where the OP is trying something similar:
JavaFX: FXML: How to make the child to extend its size to fit the parent pane?
JavaFX Panel inside Panel autoresizing
The answers suggest using only the attributes:
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
inside the child pane. I have tried this with no luck: This is what my code looks like now:
<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>
What am I missing?
Upvotes: 1
Views: 1815
Reputation: 17
I found the answer! I was searching for the same thing, but my setup is a little bit different. I used an outer scrollpane, and in that an anchorpane, and in that a splitpane, and in that an anchorpane that would stay small and hinder the splitspane from resizing. What I did to fix it was to select the SCROLLpane and set fit to width and fit to height to true. And also a couple of fit to parent.
Upvotes: 0
Reputation: 1976
I couldn't compile your code because there are errors in it. There's a missing space between the prefWidth
and orientation
parameters in the first example, and unnecessary quotation mark right before the orientation
parameter in the second example. After fixing them everything works as expected.
Here's the fixed code:
<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>
Note that you can specify prefWidth
, prefHeight
, layoutX
and layoutY
of your SplitPane, but since the anchors are set to 0, and it's the only child of the AnchorPane
, it will always take all the available space so it's redundant.
Upvotes: 1