Brikowski
Brikowski

Reputation: 149

JavaFX how to anchor nested FXML component to match parent dimensions

I'm creating an app in which I use nested FXML nodes. They are connected to parent nodes in the parent controllers using constructs like

@FXML
private AnchorPane nestedNodeConnector;

, to which I attach the child like this:

AnchorPane child = createNestedAnchorPaneWithTableViewInside();
nestedNodeConnector.getChildren().setAll((AnchorPane)child);

The code is a bit simplified, but I hopefully explained myself enough. Now my problem is that I am trying to load (as the child node) an as-large-as-possible AnchorPane with an anchored TableView inside. However I can't get this to work as the TableView dimension never sticks to the parent node (in order to grow with the window size).

I was able to get it working without nesting the child, but I really have to load the TableView in a separate FXML file. Any suggestions? I think that my approach creates an AnchorPane "child" within an AnchorPane "nestedNodeConnector", which messes up the anchor properties.

Upvotes: 0

Views: 847

Answers (1)

Brikowski
Brikowski

Reputation: 149

All I had to do was anchor the child AnchorPane (to the parent AnchorPane):

AnchorPane child = createNestedAnchorPaneWithTableViewInside();
AnchorPane.setTopAnchor(child, 10.0);
AnchorPane.setBottomAnchor(child, 10.0);
AnchorPane.setLeftAnchor(child, 10.0);
AnchorPane.setRightAnchor(child, 10.0);
nestedNodeConnector.getChildren().setAll((AnchorPane)child);

Upvotes: 1

Related Questions