Search code examples
javauser-interfaceswtreload

Java/SWT/JFace forcefull reload of 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?


Solution

  • 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.