从FXML文件中分离文本

时间:2016-05-17 06:04:14

标签: java javafx javafx-8

无论如何将节点文本与FXML文件分开? (像android一样)

<Menu mnemonicParsing="false" text="File">

例如:

<Menu mnemonicParsing="false" text="@string/mnu_file">

1 个答案:

答案 0 :(得分:3)

加载fxml时,您可以选择ResourceBundle。您可以使用fxml中的%<key>来使用资源包中的属性。

FXML

<Menu mnemonicParsing="false" text="%mnu_file">

加载代码

InputStream is = getClass().getResourceAsStream("myproperties.properties");
Parent p = FXMLLoader.load(getClass().getResource("some.fxml"), new PropertyResourceBundle(is));

myproperties.properties

mnu_file=File

另见Introduction to FXML: Resource Resolution