Changing locale at runtime in Swing

后端 未结 5 1315
再見小時候
再見小時候 2020-12-23 22:13

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 Res

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 22:45

    1. You have a method that is used to change app locale (and probably persist the new value) and another one to get localized strings.

    2. Create an interface:

      interface LocaleChangeListener {
          void onLocaleChange();
      }
      

      Implement it by UI components that need to be able to change locale at runtime and set the new values in overrides onLocaleChange().

    3. Now, have a list of listeners that will be notified on locale change by the first method.

提交回复
热议问题