适合加载的FXML的大小

时间:2017-01-03 05:41:09

标签: javafx fxml fxmlloader

我试图通过多种方式解决我的问题。但没有任何作用。

我有一个MainApplicationWindowController

@FXML
private AnchorPane mainApplicationWindow;

@FXML
private AnchorPane workAnchorPane;

@FXML
private AnchorPane workAnchorPaneContent;

和相应的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>

在workAnchorPaneContent中,我使用来自SceenManager.class的函数加载另一个FXML:

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;
}

问题是在workAnchorPaneContent中加载FXML之后,尽管设置了

,但是大小不适合workAnchorPane的大小
AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="5.0"

@Edit Jest我试图绑定大小属性。但它不适用于第二个控制器内的AnchorPane。

0 个答案:

没有答案