在 Swing 中运行时更改语言环境 [英] Changing locale at runtime in Swing

查看:24
本文介绍了在 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?

推荐答案

  1. 您有一个用于更改应用程序区域设置(并可能保留新值)的方法和另一个用于获取本地化字符串的方法.

  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.

创建接口:

interface LocaleChangeListener {
    void onLocaleChange();
}

通过需要能够在运行时更改语言环境并在覆盖 onLocaleChange() 中设置新值的 UI 组件实现它.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆