Swing I18N:何时加载属性? [英] Swing I18N: When to load properties?

查看:179
本文介绍了Swing I18N:何时加载属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重构现有的Java桌面应用程序,以从.properties文件中加载国际化的UI文本标签.在应用程序生命周期中何时才是加载属性文件并在内存中填充字符串的适当时间?现有的实现将每个组件的标签定义为例如:public static final String foo = "bar";将文本加载到构造函数中似乎效率低下(因为它将在所有实例之间共享),但是在static {...}块中执行所有操作似乎并不明智.任何一个.最佳做法是什么?

I'm refactoring an existing Java desktop application to load internationalized UI text labels from a .properties file. When in the application lifecycle is the appropriate time to load the properties file and populate the strings in memory? The existing implementation defines each component's label as e.g.: public static final String foo = "bar"; It seems inefficient to load the text in the constructor (since it'll be shared among all instances), but doing everything in a static {...} block doesn't seem remotely sane either. What's the best practice here?

推荐答案

在我看到的大多数应用程序中,在开始构建主UI之前,都是从文件中加载属性.这些属性加载到 ResourceBundle 中要么

In most applications i've seen, the properties are loaded from a file before starting to construct the main UI. These properties are loaded in a ResourceBundle which will either be

  • 静态
  • 作为每个构造函数的参数

这篇关于Swing I18N:何时加载属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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