问题描述
我正在使用德语笔记本电脑上的英语应用程序,通过西班牙语操作系统。
I am working in an English app on a german laptop, over a spanish OS.
即使我明确地将Locale.setDefault(Locale.ENGLISH)设置为开始我的应用程序,我看到菜单中的hotkexs
Even if I explictly set Locale.setDefault(Locale.ENGLISH) at the beggining of my app, I am seeing the hotkexs in the menu as
CTRL + Mayúsculas + C
而不是
CTRL + SHIFT + C
。
这个单词不仅没有像我指定的那样被本地化为英语,而且它还将SHIFT键映射到MAYUS(英语为CAPS LOCK),所以我想这不仅仅是一个语言问题,而是keymap'也是。
Is not only that word does not get localized to english as I specified, but also that it maps SHIFT key to MAYUS (CAPS LOCK in english), so I guess this is not only a language issue, but keymap´s as well.
那么如何为所有GUI组件强加英语呢?
So how can I impose english for all the GUI components?
谢谢!
推荐答案
您必须确保在执行任何工具包代码之前设置语言环境。以下代码显示了效果:如果将 Locale.setDefault(Locale.GERMAN);
移动到任何其他行,它将再次显示默认加速器名称。
You have to make sure that you set the locale before any toolkit code is executed. The following code shows the effect: if you move the Locale.setDefault(Locale.GERMAN);
to any other line it will show the default accelerator names again.
除了在代码中设置区域设置外,您还可以将以下参数附加到VM:
Instead of setting the locale inside your code you may also append the following argument to the VM:
-Duser.language=DE
public class MenuLocale {
public static void main(String[] args) {
Locale.setDefault(Locale.GERMAN);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("Menu");
JMenuItem menuitem = new JMenuItem("Menuitem");
menuitem.setAccelerator(KeyStroke.getKeyStroke('X', KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK));
f.setJMenuBar(menubar);
menubar.add(menu);
menu.add(menuitem);
f.pack();
f.setVisible(true);
}
});
}
}
这篇关于Swing中的本地化加速器(JMenuItem热键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!