2

One can set ResourceBundle in a Java class using code below.

FXMLLoader loader = new FXMLLoader(getClass().getResource("my_view.fxml"));
loader.setResources(MyRes.getBundle());    
//Node myNode = (Node) loader.load();

Is it possible to specify ResourceBundle in FXML file itself?

Stepan
  • 1,391
  • 18
  • 40

2 Answers2

3

From Introduction to FXML:

<fx:include> also supports attributes for specifying the name of the resource bundle that should be used to localize the included content, as well as the character set used to encode the source file.

<fx:include source="filename" resources="resource_file" charset="utf-8"/>

Not sure about the situation where it is not an included file as I didn't see the documentation on that (from some quick tests, I don't think it's possible, though I could be wrong).

jewelsea
  • 150,031
  • 14
  • 366
  • 406
0

Do you mean this?

<Label text="%user.firstname"/>
<Label text="%user.lastname"/>

You can use the % sign to add text from a resource file to a component in your .fxml file.

Considering that, your resource file must contain those two keys with values.

Community
  • 1
  • 1
Sunflame
  • 2,993
  • 4
  • 24
  • 48
  • Consider Controller. It can be set from POJO `loader.setController(myController);` OR from fxml `fx:controller="path.to.MyController"`. What about `loader.setResources(MyRes.getBundle());`? It can be specified in POJO, but can it be set using fxml syntax inside view.fxml? – Stepan Sep 07 '17 at 21:54
  • Okay, but at `loader.setResources()` you set your resouces for you `.fxml` file like i18n related things, or any settings that you can load from a resource file. Why do you want to set the controller from an external file? – Sunflame Sep 08 '17 at 06:56