Java FX 中的嵌套控制器问题 [英] Nested controller issue in 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?
推荐答案
FXMLLoader
将 Controller
附加到 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屋!