Fit size to loaded FXML

62 views Asked by At

I was trying to resolve my problem by many ways. But nothing works.

I have a MainApplicationWindowController

@FXML
private AnchorPane mainApplicationWindow;

@FXML
private AnchorPane workAnchorPane;

@FXML
private AnchorPane workAnchorPaneContent;

And corresponding fxml

<SplitPane dividerPositions="0.22690763052208834" layoutX="55.0" layoutY="46.0"
           prefHeight="160.0" prefWidth="200.0" styleClass="gt-splitpane"
           AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
           AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
    <items>
        <AnchorPane id="splitPaneHorizontal" maxWidth="250.0" minWidth="250.0"
                    prefWidth="250.0">
            <children>

                <TableView fx:id="gtFamilyMemberTable" layoutX="20.0" layoutY="12.0"
                           onMouseClicked="#showInfoMember" prefHeight="200.0" prefWidth="200.0"
                           AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="10.0"
                           AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="5.0">
                    <columns>
                        <TableColumn fx:id="simNameColumn" maxWidth="110.0" minWidth="110.0"
                                     prefWidth="-1.0" text="%simName"/>
                        <TableColumn fx:id="simSurnameColumn" maxWidth="110.0" minWidth="110.0"
                                     prefWidth="-1.0" text="%simSurname"/>
                    </columns>
                    <styleClass>
                        <String fx:value="firstTypeTable"/>
                        <String fx:value="tableMembersAndRelations"/>
                    </styleClass>
                </TableView>
                <TableView fx:id="gtFamilyRelationTable" layoutX="20.0" layoutY="12.0"
                           onMouseClicked="#showInfoRelation" prefHeight="200.0"
                           prefWidth="200.0" AnchorPane.bottomAnchor="40.0"
                           AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0"
                           AnchorPane.topAnchor="5.0">
                    <columns>
                        <TableColumn fx:id="relationSimLeftColumn" maxWidth="85.0"
                                     minWidth="85.0" prefWidth="-1.0" text="%relation_sim"/>
                        <TableColumn fx:id="relationTypeColumn" maxWidth="50.0" minWidth="50.0"
                                     prefWidth="-1.0" text="%relation_type"/>
                        <TableColumn fx:id="relationSimRightColumn" maxWidth="85.0"
                                     minWidth="85.0" prefWidth="-1.0" text="%relation_sim"/>

                    </columns>
                    <styleClass>
                        <String fx:value="firstTypeTable"/>
                        <String fx:value="tableMembersAndRelations"/>
                    </styleClass>
                </TableView>
                <ToggleButton fx:id="buttonShowMemberTable" layoutX="23.0"
                              mnemonicParsing="false" text="ToggleButton"
                              AnchorPane.bottomAnchor="10.0"/>
                <ToggleButton fx:id="buttonShowRelationTable" layoutX="125.0"
                              mnemonicParsing="false" text="ToggleButton"
                              AnchorPane.bottomAnchor="10.0"/>
            </children>
        </AnchorPane>
        <AnchorPane fx:id="workAnchorPane">
            <children>
                <AnchorPane fx:id="workAnchorPaneContent" styleClass="workingPane"
                            AnchorPane.bottomAnchor="40.0"
                            AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="20.0"
                            AnchorPane.topAnchor="5.0">

                </AnchorPane>
            </children>
        </AnchorPane>
    </items>
</SplitPane>

In workAnchorPaneContent I load another FXML using function from my SceenManager.class :

public FXMLPaneController loadFxml(FXMLPaneController controller, AnchorPane anchor, String fxml) {
    FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml), this.context.getBundle());
    try {
        anchor.getChildren().clear();
        anchor.getChildren().addAll((AnchorPane) loader.load());
        controller = loader.getController();
        controller.setManager(this);
        controller.setContext(this.context);
    } catch (Exception ex) {
        LOG.error(ex.getClass() + " - " + ex.getMessage());
        LOG.error(ex.getCause());
        ex.printStackTrace();
    }
    return controller;
}

The problem is that after load FXML in workAnchorPaneContent the size is not fitted to size of workAnchorPane despite setting

AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="5.0"

@Edit Jest I was trying to bind size properties. But it didn't works for AnchorPane inside second controller.

0

There are 0 answers