Internationalization and localization tools

Locale-Sensitive Java Method


public void setMnemonic(int mnemonic)

public void setMnemonic(char mnemonic)

Internationalization (I18n) Method Overview

This AbstractButton method sets the keyboard mnemonic, which is a keyboard shortcut that the user can press (usually in conjunction with the Alt key) to activate the button. The mnemonic is usually a letter associated with the label of the button itself, such as 'S' for "Submit".

The mnemonic argument passed into this method is either the int VK_XXX keycode constant, which is defined in java.awt.event.KeyEvent or a char literal that represents the mnemonic.

I18n Issues

The mnemonic key is generally the same as one of the first letters in the button label. Once the application text is localized for several languages and the correct translation pulled in at runtime, the original letter is often not a mnemonic for the new translations.

For example, the Alt+S shortcut would need to be altered for a Japanese user who instead of seeing a "Submit" button, sees a "堤出" button. Good I18n practice dictates that the mnemonic value be set dynamically according to the user's locale.

Globalyzer will detect this call and report it as an I18n issue regardless of whether mnemonic is being retrieved from a localized properties file. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.

Suggested Replacement

public void setMnemonic(char mnemonic)

Instead of:

JButton button = new JButton("Submit");


ResourceBundle bundle =
   "myBundle", locale);
JButton button = new JButton(bundle.get("submit_key"));
String mnemonic = bundle.get("mnemonic_key");

Locale-Sensitive Java Methods



Lingoport internationalization and localization services and software