设置组件区域设置不成功
我需要我的应用程序以编程方式设置所有敏感组件的区域设置,例如 JTextFields 和 JTextAreas。我还有日期信息(月份写成一个单词),它也是区域设置敏感的。
我编写了以下代码,但它似乎没有完成这项工作:
public static void setLocale(java.awt.Container c /* main form */, Locale locale /* Locale.ENGLISH */) {
Component[] components = c.getComponents();
for (Component comp : components) {
if (comp instanceof java.awt.Container)
setLocale((java.awt.Container) comp, locale);
comp.setLocale(locale);
}
}
代码有什么问题?
I need my application to set programmatically a locale of all the sensitive components, like JTextFields
and JTextAreas
. Also I have date information (month written as a word) which is locale-sensitive too.
I wrote the following code, but it doesn't seem to do the job:
public static void setLocale(java.awt.Container c /* main form */, Locale locale /* Locale.ENGLISH */) {
Component[] components = c.getComponents();
for (Component comp : components) {
if (comp instanceof java.awt.Container)
setLocale((java.awt.Container) comp, locale);
comp.setLocale(locale);
}
}
What's wrong with the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的代码应该可以解决这个问题:
但这只会对 JComponent 的新实例产生影响。
如果您想更新现有实例,请不要忘记对每个实例调用 updateUI()。
The following code should do the trick:
But this will have an effect only on new instance of JComponent.
If you want to update existing instances, don't forget to call updateUI() on each.
基本上,我不认为有理由更改区域设置
组件树中的所有组件。 由于方法
getLocale() 自动搜索其父级。
所以设置区域设置就足够了
树的根。但是否尊重语言环境
某个地方,我现在还不能说。
再见
Basically, I don't see a reason to change the locale of
all components in the component tree. Since the method
getLocale() automatically searches its parents.
So it should be enough to set the locale of the
root of the tree. But whether the locale is respected
somewhere, I can't tell right now.
Bye