Java/SWT/JFace 强制重新加载 GUI?
我有一个应用程序应该可以更改其语言而无需重新启动。它已经使用了不同语言的资源包,但是由于菜单项和其他 GUI-stuf 是在程序启动的前几秒钟内生成的,因此我以后无法再更改它们的内容。
知道我能做什么吗?或者我是否必须跟踪每个可能的 GUI 相关项目?
I have an app that is supposed to change its language without having to restart. It already uses Resourcebundles for different languages, but since the Menu-Items and other GUI-stuf gets generated during the first few seconds of the program start, I can't change their Content any more aterwards.
Any Idea what I could do? Or do I have to keep track of every possible GUI-related item?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种简单的选择是从头开始重新创建 UI,而无需重新启动应用程序。
例如,您可以隐藏旧的 Shell,然后显示状态相同但语言不同的新 Shell。
如果这也不被接受...我在这里推测...也许您可以使用 Widget.setData( String, Object ) 为每个小部件存储本地化密钥,然后在切换语言时使用 Composite.getChildren() 遍历小部件树-- 从 Shell 开始 -- 并使用 Widget.getData(String) 获取每个小部件的资源键。但是,单个小部件可能有多个与其关联的可本地化字符串。
One easy option would be to recreate the the UI from scratch -- without restarting the application.
For example, you could hide the old Shell, then show a new one with the same state but different language.
If that's not accepted either ... I'm speculating here ... maybe you could store a localization key for each widget with Widget.setData( String, Object ), then when switching languages traverse the widget tree with Composite.getChildren() -- starting with the Shell -- and use Widget.getData(String) to get resource keys for each widget. However, a single widget might have multiple localizable strings associated with it.
是的,您应该保留引用 GUI 对象的对象,以便在用户选择新语言时可以更新其文本。
Yes, you should keep objects that reference the GUI objects so you can update their text when a user selects a new language.