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

前端 未结 6 1303
广开言路
广开言路 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 08:44

    You could try with setting prefWidth. I don't know why, but it seems like it takes the prefWidth which is set in SceneBuilder after referencing your newPane to your AnchorPane.

    Node newPane = FXMLLoader.load(getClass().getResource("view/YourPane.fxml"));
    List parentChildren = ((Pane)yourAnchorPaneId.getParent()).getChildren();
    parentChildren.set(parentChildren.indexOf(yourAnchorPaneId), newPane);
    yourAnchorPaneId.setPrefWidth(1800); // 1800 just example value for test
    Main.primaryStage.setWidth(500); // 500 example value with which you wishe to start app
    

提交回复
热议问题