JavaFX: FXML: How to make the child to extend its size to fit the parent pane?

前端 未结 6 1301
广开言路
广开言路 2020-12-14 08:18

I have managed to load a child fxml(sub UI) under a parent fxml (mainMenu UI). I have created an AnchorPane with id \"mainContent\". This pane is bound to 4 sides and change

6条回答
  •  生来不讨喜
    2020-12-14 09:00

    If you have a Region, which is a subclass of Node that includes Axis, Chart, Control, and Pane (this probably includes anything you might want to load), you can bind the child's size to the space in the parent similar to how they did here. Now any future adjustments of the parent's size will be reflected in the child.

    Region n = (Region)loader.load();
    mainContent.getChildren().add(n);
    n.prefWidthProperty().bind(mainContent.widthProperty());
    n.prefHeightProperty().bind(mainContent.heightProperty());
    

提交回复
热议问题