Java FX 中的嵌套控制器问题 [英] Nested controller issue in Java FX

查看:34
本文介绍了Java FX 中的嵌套控制器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的主布局 (main.fxml) 中包含控制器 (SelectedIssueController).但我收到以下错误:

I'm trying to include controller(SelectedIssueController) in my main layout (main.fxml). But I get the following error:

Can not set lt.mypackage.controllers.SelectedIssueController field lt.mypackage.controllers.MainController.selectedIssueController to javafx.scene.layout.VBox

main.fxml 中的行:

Line in main.fxml:

  <fx:include fx:id="selectedIssueController" source="controllers/selectedissue.fxml" />

我选择的issue.fxml:

My selectedissue.fxml:

<VBox xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="lt.mypackage.controllers.SelectedIssueController" fillWidth="false" SplitPane.resizableWithParent="false">
    <children>
     .....
     .....
    </children>
</VBox>

MainController 中的行:

@FXML
private SelectedIssueController selectedIssueController;

据我所知,它现在注入 VBox 对象,但我需要 SelectedIssueController.我目前的实施有什么问题?

As I understand it injects VBox object now, but I need SelectedIssueController. What is wrong with my current implementation?

推荐答案

FXMLLoaderController 附加到 fx:id 中指定的fx:include 元素以获取要注入控制器的字段的名称.因此它应该是:

The FXMLLoader appends Controller to the fx:id specified in the fx:include element to get the name of the field to inject the controller to. Therefore it should be either:

@FXML
private SelectedIssueController selectedIssueControllerController;

<fx:include fx:id="selectedIssue" source="controllers/selectedissue.fxml" />

注入没有Controller后缀的字段的值是为fx:include创建的值,即为Object创建的包含的 fxml 的根目录.

The value injected to the field without the Controller suffix is the value created for the fx:include, i.e. the Object created for the root of the included fxml.

这篇关于Java FX 中的嵌套控制器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆