Search code examples
javajavafxlayoutresponsiveautosize

Resize newly added child into parent in JAVAFX


Good night, I've run into a problem where I have an application form that I created, the main Stage has buttons to load different fxml into the app, which then are added into a secondary anchorPane, the problem is that these newly added child anchorPanes are not auto-resizing, even after playing around with the Layout Constrains.

I'm using Java 8 and IntelliJ / SceneBuilder

Main Stage Controller: main_stage_controller

App running in default size: app_1

App after resizing: app_2

I have searched everywhere and can't seem to find a solution, thanks!


Solution

  • Adding the following lines to the child FXML loaded pane fixed it:

    AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
    

    Now the app resizes and centers the newly loaded anchorPanes.