-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.4, 1.2.0
-
generic, x86
-
generic, windows_nt
Name: joT67522 Date: 11/17/97
On NT4 using JDK114 the MenuShortCuts ctrl+\ and ctrl+/ do not generate action events.
Also some combinations of keys generate action events which they should not. If you
MenuShortCuts keys of ctrl+N,ctrl+C and ctrl+T the following combination of keys will
generate false actions events, blaming the MenuItem with the related shortcut.
ctrl + numericpad fullstop -----> ctrl+N
ctrl + numericpad 3 ------> ctrl+C
ctrl + F5 ------> ctrl+T
Sourcecode to generate the above:
// A Stand alone Test case to show MenuShortCut Items don't work properly
import java.awt.*;
import java.awt.event.*;
public class MenuShortCutTest extends Frame implements ActionListener
{
private MenuBar menu_bar;
private Menu main_menu;
private MenuItem selectall_item,deselectall_item,test_item,cp_item,new_item;
private TextField text_field;
public static void main(String[] args)
{
new MenuShortCutTest();
}
public MenuShortCutTest()
{
// Text Field
text_field = new TextField();
add(text_field);
// Set Up Menu Bar
menu_bar=new MenuBar();
this.setMenuBar(menu_bar);
main_menu = new Menu("Main");
// Select All
selectall_item = new MenuItem("SelectAll", new MenuShortcut(KeyEvent.VK
_SLASH));
main_menu.add(selectall_item);
selectall_item.addActionListener(this);
// DeSelect All
deselectall_item = new MenuItem("DeselectAll", new MenuShortcut(KeyEven
t.VK_BACK_SLASH));
main_menu.add(deselectall_item);
deselectall_item.addActionListener(this);
// Test
test_item = new MenuItem("Test", new MenuShortcut(KeyEvent.VK_T));
main_menu.add(test_item);
test_item.addActionListener(this);
// Copy and Paste
cp_item = new MenuItem("Copy+Paste", new MenuShortcut(KeyEvent.VK_C));
main_menu.add(cp_item);
cp_item.addActionListener(this);
// New
new_item = new MenuItem("New", new MenuShortcut(KeyEvent.VK_N));
main_menu.add(new_item);
new_item.addActionListener(this);
menu_bar.add(main_menu);
setSize(500,200);
show();
}
public void actionPerformed (ActionEvent e)
{
Object o = e.getSource();
text_field.setText("Action performed by"+o.toString());
}
}
(Review ID: 19665)
==================
====================================================
erik.larsen@Eng 1998-05-27
import java.awt.*;
import java.awt.event.*;
public class FooBar extends Frame implements ActionListener
{
public static void main(String[] args)
{
FooBar f = new FooBar();
f.pack();
f.show();
}
public FooBar()
{
MenuBar mb = new MenuBar();
Menu m = new Menu("File");
MenuShortcut ms = new MenuShortcut((int) "O".charAt(0));
MenuItem mi = new MenuItem("Open", ms);
mi.addActionListener(this);
m.add(mi);
mb.add(m);
setMenuBar(mb);
}
public void actionPerformed(ActionEvent e)
{
// Here's the problem. If I click on Open,
// I get the expected response. If I use the
// shortcut, I get a NullPointerException due to
// the call to getActionCommand.
if (e.getActionCommand().equals("Open"))
{
System.out.println("Yeah, I'll think about it");
}
}
}
- duplicates
-
JDK-4034665 Can't set MenuShortcuts using function key (VK_F1...F12) and other key codes
-
- Resolved
-