1

I have an application written on JavaFX (with using of FXML). I'm trying to internatiolize my app. I was trying to do it like it is described in this tutorial.

I have a property file with text like this: submit=Войти

I have a button, described in FXML:

<Button id="button1" fx:id="submit" layoutX="69.0" layoutY="200.0" onAction="#loginFired" prefHeight="45.0" prefWidth="97.0" text="\%submit" />

Property file and fxml file are in the same directory.

But my button do not have a text, i expect it to have, it is written "%submit" on it, but not "Войти". Then i've tried to do something like in this one tutorial In my intialize method i have suh code:

@Override
public void initialize(URL arg0, ResourceBundle resources) {
    if(resources == null)
        System.out.println("error");
}

and it gives me an "error" message to the log.

So, what am i doing wrong?

Community
  • 1
  • 1
Victoria Agafonova
  • 2,048
  • 10
  • 33
  • 50

1 Answers1

4
text="\%submit"

\ character means escape the next character which is % in this case, resulting to be written as "%submit" in the output. So correct usage is text="%submit".

If you are loading FXML file using the FXMLLoader then do not forget to set the resource as well:

fxmlLoader.setResources(ResourceBundle.getBundle("bundles.MyBundle", locale));

look again the JavaFX 2 and Internationalization for full example.
Also check the result of ResourceBundle.getBundle("bundles.MyBundle", locale) for not being null.

Community
  • 1
  • 1
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • As this one statement *if(resources == null)* shows, my ResourceBundle resources is null. And a question is what am i doing wrong that it is null? – Victoria Agafonova May 16 '12 at 08:11
  • 1
    Either you are not setting the resource through `fxmlLoader.setResources()` or `ResourceBundle.getBundle("bundles.MyBundle", locale)` is returning null. There maybe other reasons of course. – Uluk Biy May 16 '12 at 08:16