开发者

swt seamless language change

I hav开发者_开发问答e an SWT application which is quite complex at the moment. And I want to make the app able to switch interface languages without restarting. What is the best way to do it?


The Control API (which is the superclass for all SWT components) has a method redraw(), which, I assume, calls the create contents method again and should provide the result you are looking for.

EDIT: I just tested this by making a button and setting its text to a random number after each push, and it works without any aesthetic side-effects.


There are typical three parts to a solution:

  • the language files
  • the static text for Controls
  • the dynamic text.

The language files are just plain Java properties files - see the java.text package. When you change language, you "just" open a new Locale.

The static text for Controls - e.g. Button and Labels - are often handled by associating a key to each Control that should be able to change language. When you want to change language, you recursively go through the Controls, lookup the new text in the current locale and set the new value...

The dynamic text is... everything else... This is usually handled by using format string - see String.format(...) - again retrieved from the current locale.

And of cause there are other things that might be dependent on the current language - e.g. icons, images, media clips, etc....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜