How to update the language of a JavaFX application at runtime

1

I have a combobox that contains the languages, when selecting it stores and I would like to already apply the language update.

But I wanted to do it dynamically. The problem is that I do not know how to change the language.

This method is calling when the combo option is selected

 languages.valueProperty().addListener(new ChangeListener<Locale>() {
            @Override
            public void changed(ObservableValue<? extends Locale> observable, Locale oldValue, Locale newValue) {
                LanguageEnum le = CommonService.fromLocale(newValue);
                try {
                    CommonService.setLanguage(le);
                    refreshRender(CommonService.getBundle());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

In this method I would render the opened screens with the selected language, the intention was to see which scene was visible, and change their language, however I would need to know the fxml that was loaded to give the load again.

I do not know if this is the case, and I do not know how to conclude, because I could not find a method to retrieve the URL of the scene instance that was used, I do not know if this is the best way, the goal is to change the language based on the language selected in the combo and already apply the translation on the screen. I started studying JavaFX last week so I'm pretty much lost.

   private void refreshRender(ResourceBundle bundle) {
        ObservableList<Stage> stages = StageHelper.getStages();
        for (Stage s : stages) {
            if (!s.isShowing()) {
                continue;
            }
            Scene scene = s.getScene();
            Parent root = scene.getRoot();
    FXMLLoader.load(getClass().getResource("xxxx.fxml"), bundle);
        }
    }
    
asked by anonymous 13.08.2017 / 18:17

0 answers