我按照... / 40836043 / javafx-access-fxid-from-nested-fxml的线程添加了对2 ...控制器类之间的字段的访问,同时使用了fx:include结构,但我似乎步陷入问题:
我的voxeledit.fxml(VoxelEdit.java的root fxml文件)是
<VBox minHeight="766.0" .....
....
<fx:include source="VoxelEditModelTabs.fxml" fx:id="modeltabsController" />
....
</VBox>
和关联的Controller java是
public class VoxelEditController implements Initializable {
@FXML private VoxelEditModelTabsController modeltabsController;
....
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println( ". VoxelEditController initializing ..." );
System.out.println( ". VoxelEditController voxeleditModeltabsController is: "+modeltabsController );
....
然后嵌入式fxml的控制器是
public class VoxelEditModelTabsController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println( ". VoxelEditModelTabsController initialized" );
}
private final ReadOnlyStringWrapper status_msg = new ReadOnlyStringWrapper();
public ReadOnlyStringProperty status_msg_Property() {
return status_msg.getReadOnlyProperty() ;
}
....
运行主应用程序时,它会在主要初始化过程中的一些调试消息后停止
*** VoxelEdit main started
* VoxelEdit start entered
. VoxelEditMenuController initializing
. VoxelEditColorSelectionController initialized
. VoxelEditModelTabsController initialized
Exception in Application start method
....
Caused by: java.lang.IllegalArgumentException: Can not set voxeledit.VoxelEditModelTabsController field voxeledit.VoxelEditController.modeltabsController to javafx.scene.layout.AnchorPane
如果我从fx:include中删除fx:id,app会运行,但VoxelEditController类中的字段modelTabs保持为NULL。
由于消息“无法设置......”并没有真正帮助,我不知道出了什么问题。我将所有fx:include件合并为一个大的fxml然后应用程序运行,但这不是我认为应该是模块化开发(顺便说一下,fxml文件有超过1500行)!
请帮我解决这个问题。