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

Dean Chiu

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 changes in accords to the stage.

The child window will be loaded into the "mainContent" anchorpane. However, I can't figure out how to make the child to change along with its parent "mainContent".

My child UI is called like this.

@FXML
private void mnuUserLevel_onClick(ActionEvent event) {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("DBedit.fxml"));
    loader.setController(new DBeditEntityUserlevel());

    try {
           Node n = (Node)loader.load();
           mainContent.getChildren().add(n);
    } catch (IOException e){
           System.out.println(e.getMessage());
    }
}

To further illustrate my question, please see my snap shot. The red square is the child. The yellow square is the "mainContent" AnchorPane of the MainMenu parent.

enter image description here

Sascha B

If you set the static methods setTopAnchor( child, value ), setBottomAnchor( ... ), setLeftAnchor( ... ), setRightAnchor( ... ) of class AnchorPane to 0.0, the child Node will get stretched to the full extend of the parent AnchorPane.

Documentation Link: AnchorPane

edit: in the documentation link you can also see how you can set these values in your java code.

FXML example:

<AnchorPane fx:id="mainContent" ...>
<StackPane fx:id="subPane" AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" ></StackPane>
</AnchorPane>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to make child auto-resize (child is Pane, parent is VBox) in javafx

From Dev

How to extend custom JavaFX components that use FXML

From Dev

Make child div fit its content while its parent has scrollbars?

From Dev

How to make the tabs of QTabWidget fit the size of the container - Adjust its lenght?

From Dev

How to change parent of child fxml into other parent?

From Dev

How to change parent size in Windows forms by its child?

From Dev

Vbox Parent, Pane Child overlapping other components javafx

From Dev

How to make a flex child overflow its parent as it grows?

From Dev

Android: How to change dynamically size of child views to fit parent view size?

From Dev

Android: How to change dynamically size of child views to fit parent view size?

From Dev

JavaFX access parent Controller class from FXML child

From Dev

How to make child div to take the size of parent div

From Dev

How can I make a ring in JavaFX (fxml)

From Dev

How do I make a div extend its width beyond the parent's width?

From Dev

How to make flexbox child's height to fit to content instead of 100% height of its container

From Dev

How to make the parent element fit its floated children as long as they aren't wider than the window?

From Dev

How can I make multiple Path elements inside a Canvas scale to fit its parent?

From Dev

ScalaFX : How to stretch ScrollPane to fit its parent

From Dev

How do I make the larger child divs to always fit in the parent div?

From Dev

How to fit resizable child div to his parent

From Dev

How to make the image scale its size automatically according to the parent JLabel's size, in Netbeans GUI Builder?

From Dev

Make a graph of Qt widgets that extend outside its parent window

From Dev

Make a <button> fill the whole width and (!) extend its container's size

From Dev

javafx & fxml: how do I apply a border to a pane or label in my gui?

From Dev

JavaFX: make a vertical ScrollBar fit to parent node in TableView

From Dev

How to make ul extend past parent div?

From Dev

How to make table fit window in javafx

From Dev

How to make javafx label fit text?

From Dev

How to make table fit window in javafx

Related Related

  1. 1

    how to make child auto-resize (child is Pane, parent is VBox) in javafx

  2. 2

    How to extend custom JavaFX components that use FXML

  3. 3

    Make child div fit its content while its parent has scrollbars?

  4. 4

    How to make the tabs of QTabWidget fit the size of the container - Adjust its lenght?

  5. 5

    How to change parent of child fxml into other parent?

  6. 6

    How to change parent size in Windows forms by its child?

  7. 7

    Vbox Parent, Pane Child overlapping other components javafx

  8. 8

    How to make a flex child overflow its parent as it grows?

  9. 9

    Android: How to change dynamically size of child views to fit parent view size?

  10. 10

    Android: How to change dynamically size of child views to fit parent view size?

  11. 11

    JavaFX access parent Controller class from FXML child

  12. 12

    How to make child div to take the size of parent div

  13. 13

    How can I make a ring in JavaFX (fxml)

  14. 14

    How do I make a div extend its width beyond the parent's width?

  15. 15

    How to make flexbox child's height to fit to content instead of 100% height of its container

  16. 16

    How to make the parent element fit its floated children as long as they aren't wider than the window?

  17. 17

    How can I make multiple Path elements inside a Canvas scale to fit its parent?

  18. 18

    ScalaFX : How to stretch ScrollPane to fit its parent

  19. 19

    How do I make the larger child divs to always fit in the parent div?

  20. 20

    How to fit resizable child div to his parent

  21. 21

    How to make the image scale its size automatically according to the parent JLabel's size, in Netbeans GUI Builder?

  22. 22

    Make a graph of Qt widgets that extend outside its parent window

  23. 23

    Make a <button> fill the whole width and (!) extend its container's size

  24. 24

    javafx & fxml: how do I apply a border to a pane or label in my gui?

  25. 25

    JavaFX: make a vertical ScrollBar fit to parent node in TableView

  26. 26

    How to make ul extend past parent div?

  27. 27

    How to make table fit window in javafx

  28. 28

    How to make javafx label fit text?

  29. 29

    How to make table fit window in javafx

HotTag

Archive