JavaFX8 fxml嵌套控制器的命名 [英] JavaFX8 fxml naming of nested controllers

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

问题描述

给定.fxml包含如下:

Given an .fxml include like:

<fx:include fx:id="header" source="Header.fxml" />

Java FXML docs 说要创建两个变量,如:

The Java FXML docs say to create two variables like:

@FXML private HBox header;
@FXML private HeaderController headerController;

什么决定了控制器变量名?是总是只是包含ID后跟Controller?

What determines the controller variable name? Is it always just the include id followed by "Controller"?

推荐答案

是的字段名称是注入控制器总是通过连接< fx:include> 标记的 fx:id 来构造code>控制器。

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 字段


包含fxml文件的控制器的后缀。完整密钥存储在命名空间映射中。

A suffix for controllers of included fxml files. The full key is stored in namespace map.

(命名空间映射包含按字段名称注入的所有对象to,如果存在这样的字段。)

你可以验证它的值是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屋!

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