简体   繁体   English

FXML如何在单个FXML文件中嵌套控制器

[英]FXML How do I have nested controllers in a single FXML file

I have read some posts that talk about nested FXML controllers in the context of FXML include files. 我已经阅读了一些有关FXML包含文件上下文中的嵌套FXML控制器的文章。 However my problem is that I have one FXML file with multiple classes defined. 但是,我的问题是我有一个定义了多个类的FXML文件。

To put my problem simply. 简单来说就是我的问题。 How can I do with one single FXML file the equivalent to running the makeMe() in the example below. 如何处理一个FXML文件,相当于在下面的示例中运行makeMe()。

public class ClassA{
   // something
}

public class ClassB{
   public ClassA myAClass;
}

public void makeMe{
   ClassB myBClass;
   myBClass = new ClassB();
   myBClass.myAClass = new CLassA();
}

Try it if it does. 如果可以,请尝试。

<Header fx:id="header" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
    <chartWindow>
        <Block count="4" type="Short" />
    </chartWindow>
    <measurement>
        <Block count="6" type="Short" />
    </measurement>
</Header>

In this situation, Header should look like this 在这种情况下, Header应如下所示

public class Header extends Block {

    private Block chartWindow;

    private Block measurement;

    public Block getChartWindow() {
        return chartWindow;
    }

    public void setChartWindow(Block block) {
        this.chartWindow = block;
    }

    public Block getMeasurement() {
        return measurement;
    }

    public void setMeasurement(Block block) {
        this.measurement = block;
    }
}

So in the controller you only have a Header instance 因此,在控制器中,您只有Header实例

public class Controller {
    @FXML
    private Header header;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM