5

I've started toying with JavaFX 2 and I really like the ease with which one can create a UI with FXML. However, once you get past the basic examples and you need a UI with many windows, it seems illogical to have the definition for the whole application's UI in a single FXML file.

Is it possible to write separate components in separate FXML files and then include them as needed? Say for example that I wanted a window to popup when the user clicks on an item from the main menu; could I write the definition for that window in a separate FXML file, load it at runtime and add it to the node tree?

4

1 回答 1

4

从 FXML 的角度来看,有两种方法:

  1. 只需使用fx:include指令将应用程序拆分为不同 fxml 文件中的逻辑部分。

  2. 更高级的方法是将应用程序的部分实现为单独的“控件”。它将有自己的(可能非常简单)API 来提供数据,并且可以在 FXML 或 FX API 中使用,如内置控件。有关如何使用 FXML 实现该功能的详细信息,请参阅下一个问题:How to pass object created in FXML Controller1 to Controller2 of inner FXML control

于 2012-10-01T09:52:50.057 回答