将子代添加到fx:java fxml中的root元素的子代中

问题描述 投票:0回答:1

我有一个问题,因为我知道如何将新组件添加到fx:root容器子级。

这是我目前所拥有的。

根元素称为PopupContainer

<fx:root type="StackPane" alignment="CENTER" xmlns:fx="http://javafx.com/fxml"
     styleClass="popup">
    <VBox alignment="CENTER">
        <HBox alignment="CENTER">
            <VBox fx:id="content" alignment="CENTER" spacing="5" styleClass="whiteBackground, blackborder"
              fillWidth="false" StackPane.alignment="CENTER">
            <!-- this is where I would like to add components -->
            </VBox>
        </HBox>
    </VBox>
</fx:root>

我也有它的控制器。

现在,我想在其他fxml中像这样使用它:

<PopupContainer xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="solutions.lunalabs.blagajna.base.nastavitve.nastavitvesifrant.bank.editbank.EditBankPresenter"
            styleClass="popup"
            fx:id="container">
    <!-- those components should go to VBOX up there -->
    <ViewTitle label="%editBankUC"/>
    <Button fx:id="someButton" text="Click me"/>
</PopupContainer>

当然,当我添加组件时,它们直接位于StackPane下,因为它是布局的根目录。我试图重写getChildren()方法以返回VBox子级,但是检测到了子级周期。我不想以编程方式添加它们,因为在应用程序中有300多个此类案例,但是我可以添加新标签(而不是其他示例)。谢谢!

java fxml
1个回答
0
投票

回答我自己的问题,因为我想其他人也想知道这一点。

所以,就像我以前所拥有的,这是PopupContainer.fxml:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.geometry.Insets?>
<fx:root type="StackPane" alignment="CENTER" xmlns:fx="http://javafx.com/fxml"
         styleClass="popup">
    <VBox fx:id="child1" alignment="CENTER">
        <HBox alignment="CENTER">
            <VBox fx:id="content" alignment="CENTER" spacing="5" styleClass="whiteBackground, blackborder"
                  fillWidth="false" StackPane.alignment="CENTER">

                <padding>
                    <Insets topRightBottomLeft="10.0" />
                </padding>
            </VBox>
        </HBox>
    </VBox>
</fx:root>
© www.soinside.com 2019 - 2024. All rights reserved.