我正在构建一个支持多语言的 JavaFX 应用程序。因此,在通过以下方式加载 fxml
文件时:
AnchorPane page = (AnchorPane) FXMLLoader.load(Main.class.getResource("fxml/RealTimeInitialPanel.fxml"),Language.getBundle());
我正在根据默认语言
传递资源包。上面的 Language
类扩展了 ResourceBundle 并返回基于当前 Locale 的 String。要更改语言,我只需调用 Language.setLocale(..)
。一切正常。
但是现在假设用户在旅途中更改语言。如何向 fxml 或 UI 发出信号以刷新屏幕。这样他们将再次调用 getString(..)
并且文本会根据 setLocale 进行更新。在 Swing 中,它会定期刷新。但是有了 fx,我无法
最佳答案
根据 Benefits of FXML , 事无 3:
The content of an FXML file can be localized as the file is read. For example, if an FXML file is loaded using the en_US locale, then it produces the string "First Name" for a label based on the following resource string: If the locale is changed to fr_FR and the FXML file is reloaded, then the label shows "Prénom." ...
因此,如果您的目标是通过 FXMLLoader
本地化应用程序,那么我认为除了重新加载之外,您无法向 FXML 发出刷新其捆绑文本的信号。
关于java - JavaFX 中语言更改的刷新屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14622652/