Reputation: 957
I have a SplitPane with a TreeView on the left and a content area on the right. When I click on an item in my TreeView I want to display content on the right. How I do this now is to load an FXML which I create in SceneBuilder. My problem is that the FXML doesn't fit to the SplitPane. This is how I load the FXMl file
if (selectedItem.getValue() == "Sample") {
try {
AnchorPane pane = (AnchorPane) FXMLLoader.load(getClass().getResource("Sample.fxml"));
splitPane.getItems().set(1, pane);
} catch (IOException e) {
e.printStackTrace();
}
}
How do I make this AnchorPane which I created to fit to the original SplitPane size?
Upvotes: 0
Views: 3582
Reputation: 11
I have been struggling with this as well, I finally solved by problem by avoiding nested wrapping of AnchorPanes. I've removed the AnchorPane as the child container of the SplitPane, because the root of the included FXML also starts with an AncherPane:
Now my main FXML has something like:
<SplitPane>
<items>
<fx:include fx:id="navigationPanel" source="FX2NaviPanel.fxml"/>
<fx:include fx:id="dataPanel" source="FX2dataPanel.fxml"/>
</items>
</SplitPane>
and each child FX2NaviPanel.fxml and FX2dataPanel.fxml still start with an AnchorPane:
<AnchorPane ...>
<children>
<GridPane></GridPane>
</children>
</AnchorPane>
With this and appropriate maximum sizes, and fit-to-parent and zero-anchors where relevant the panels nicely stick to the movement of the splitter and resizing of the main window.
Upvotes: 1
Reputation: 1117
Aligning in FX is a pain i.t.a.
I suggest the following:
<SplitPane>
<TreeView /> //LEFT
<ANCHORPANE AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> //RIGHT, anchors make the content stick to the corner
<AnchorPane fx:id="myDynamicContent"/>
</ANCHORPANE>
</SplitPane>
With this the inner pane myDynamicContent should be stretched to all corners. Please tell if this is the answer.
You can also try to set the AncorPane.* attributes ON your content so you dont need nested AnchorPane.
Edit: After thinking about it I think you need the outer pane because it is "THE CONTAINER", without it the inner pane does not what to stick to.
Upvotes: 0