在Swing中改变运行时的语言环境 [英] Changing locale at runtime in Swing
问题描述
我希望能够在运行时更改Swing应用程序中的语言环境,并让屏幕上的所有文本元素都使用新语言环境的ResourceBundle中的本地化文本进行更新。
I would like to be able to change the locale in my Swing application at runtime and have all the text elements on the screen update themselves with localized text from a ResourceBundle of the new locale.
这可以在不自定义swing组件或为处理渲染本地化文本的所有组件创建UIDelegates的情况下完成吗?
Can this be done without customizing swing components or creating UIDelegates for all components that handle rendering localized text?
如果不是,那么我可以考虑实施什么是一个好的解决方案?
If no, then what is a good solution I can consider implementing?
推荐答案
-
你有一个方法用于更改应用程序区域设置(可能会保留新值),另一个用于获取本地化字符串。
You have a method that is used to change app locale (and probably persist the new value) and another one to get localized strings.
创建一个界面:
interface LocaleChangeListener {
void onLocaleChange();
}
通过需要能够在运行时更改语言环境的UI组件实现它在覆盖中设置新值 onLocaleChange()
。
Implement it by UI components that need to be able to change locale at runtime and set the new values in overrides onLocaleChange()
.
现在,有一个将要监听的侦听器列表通过第一种方法通知地区变更。
Now, have a list of listeners that will be notified on locale change by the first method.
这篇关于在Swing中改变运行时的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!