Stepan
Stepan

Reputation: 1431

Specify ResourceBundle within FXML file in JavaFX

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?

Upvotes: 2

Views: 4065

Answers (2)

Sunflame
Sunflame

Reputation: 3186

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.

Upvotes: 1

jewelsea
jewelsea

Reputation: 159291

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).

Upvotes: 4

Related Questions