-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.5, 1.2.2
-
generic, x86
-
generic, windows_nt
Name: rm29839 Date: 12/17/97
There is a line of code in KeyEvent in the constructor.
public MenuShortcut(int key, boolean useShiftModifier) {
// Convenience conversion for programmers who confuse key posts with
// ASCII characters -- do not internationalize! They *should* be
// using KeyEvent virtual keys, such as VK_A.
if (key >= 'a' && key <= 'z') {
key = (int)Character.toUpperCase((char)key);
}
this.key = key;
this.usesShift = useShiftModifier;
}
Since above you are comparing the key with the chars
a-z function keys and certain other keys are converted
to uppercase. Example;The F5 key is converted to
uppercase X when given to the shortcut.
The conveniance line above needs to be removed!
(Review ID: 22038)
======================================================================
import java.awt.*;
import java.awt.event.*;
public class test extends Frame implements ActionListener {
MenuItem mi;
public test () {
MenuBar menubar = new MenuBar();
Menu menu = new Menu("File");
// Add a menu item using the VK_F1 for a function key.
//
mi = new MenuItem("A", new MenuShortcut(KeyEvent.VK_F1));
menu.add(mi);
mi.addActionListener(this);
menubar.add(menu);
setMenuBar(menubar);
setBounds(0, 0, 200, 200);
show();
}
public void actionPerformed(ActionEvent event) {
if ( event.getSource() == mi ) {
System.out.println("Beep!");
}
}
public static void main(String args[]) {
new test();
}
}
Description of Problem:
Function keys cannot be used as menu shortcuts.
Problem Analysis:
MenuShortcut contains a "convenience conversion" that breaks the
java spec. and causes this bug. Some code has been added to
the MenuShortCut constructor for "programmers who confuse key
posts with ASCII characters" - essentially so that MenuShortCuts
can be called with lowercase ASCII chars instead of KeyEvent virtual
keys like it is supposed to be. This conversion is:
if (key >= 'a' && key <= 'z') {
key = (int)Character.toUpperCase((char)key);
this.key = key;
this.usesShift = useShiftModifier;
}
So, if MenuShortCut is called correctly with a KeyEvent.VK and
this KeyEvent.VK happens to have a value between 'a' and 'z',
then the key is converted to something else. Function keys
have KeyEvent.VK values that translate to between 'a' and 'z'
(e.g. F1 = 0x70 = 'p') hence this problem.
keith.troy@Ireland 1999-09-02
- duplicates
-
JDK-4269825 accelerators using Function keys displayed incorrectly
-
- Closed
-
-
JDK-4034665 Can't set MenuShortcuts using function key (VK_F1...F12) and other key codes
-
- Resolved
-