嵌套控制器的 JavaFX8 fxml 命名 [英] JavaFX8 fxml naming of nested controllers
问题描述
给定一个 .fxml 包括:
Given an .fxml include like:
<fx:include fx:id="header" source="Header.fxml" />
Java FXMLdocs 说要创建两个变量,例如:
The Java FXML docs say to create two variables like:
@FXML private HBox header;
@FXML private HeaderController headerController;
控制器变量名由什么决定?是否总是只是包含 ID 后跟控制器"?
What determines the controller variable name? Is it always just the include id followed by "Controller"?
推荐答案
是的,控制器注入的字段名称总是通过连接 <fx 的
带有 fx:id
来构造:include>"Controller"
的标签.
Yes the field name the controller is injected to is always constructed by concatenating the fx:id
of the <fx:include>
tag with "Controller"
.
它隐藏"在 的文档中FXMLLoader.CONTROLLER_SUFFIX
字段.
It's "hidden" in the documentation of the FXMLLoader.CONTROLLER_SUFFIX
field.
包含的 fxml 文件的控制器的后缀.完整的键存储在命名空间映射中.
A suffix for controllers of included fxml files. The full key is stored in namespace map.
(命名空间映射包含所有对象,根据它们被注入的字段名称,如果存在这样的字段.)
您可以在此处验证它的值为 "Controller"
:https://docs.oracle.com/javase/8/javafx/api/constant-values.html#javafx.fxml.FXMLLoader.CONTROLLER_SUFFIX
You can verify that it's value is "Controller"
here: https://docs.oracle.com/javase/8/javafx/api/constant-values.html#javafx.fxml.FXMLLoader.CONTROLLER_SUFFIX
这篇关于嵌套控制器的 JavaFX8 fxml 命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!