-
Bug
-
Resolution: Duplicate
-
P2
-
None
-
1.2.2_005
-
None
-
x86
-
generic
I have a menubar that contains a certain menu. This menu has several menuitems.
One of these menuitems has the same mnemonic as the menu itself.
When I press Alt-(this same mnemonic), normally it must open the menu so I can
choose the menuitem myself. But unfortunatly, it sends directly the action related to the menuitem having this mnemonic, without opening the menu. Which is completely incoherent.
The problem is seen in Java 1.2.2-005, but not in Java 1.3.0-C where is works
correctly
Test case:
I sent you a example that shows the problem.
After launching the example, see the menuitems in the menubar.
Then try to type Alt-F, it opens directly a JOptionPane telling that the FROM
menuitem has been fired. Normally, it must open then File menu without firing anything.
-----
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MnemonicTest{
JFrame frame;
public MnemonicTest(){
frame=new JFrame();
JLabel label=new JLabel("Testing");
frame.getContentPane().add(label);
JMenuBar menuBar=new JMenuBar();
MenuActionListener menuActionListener=new MenuActionListener();
JMenu fileMenu=new JMenu("File");
fileMenu.setMnemonic('F');
JMenu editMenu=new JMenu("Edit");
editMenu.setMnemonic('E');
JMenuItem toMenuItem=new JMenuItem("To");
toMenuItem.setMnemonic('t');
toMenuItem.addActionListener(menuActionListener);
JMenuItem fromMenuItem=new JMenuItem("From");
fromMenuItem.setMnemonic('f');
fromMenuItem.addActionListener(menuActionListener);
fileMenu.add(toMenuItem);
fileMenu.add(fromMenuItem);
JMenuItem viewMenuItem=new JMenuItem("View");
viewMenuItem.addActionListener(menuActionListener);
viewMenuItem.setMnemonic('v');
editMenu.add(viewMenuItem);
menuBar.add(fileMenu);
menuBar.add(editMenu);
frame.setJMenuBar(menuBar);
frame.setSize(new Dimension(200, 200));
frame.setVisible(true);
}
public class MenuActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(frame, "Selected MenuItem is "+e.getActionCommand());
frame.repaint();
}
}
public static void main(String args[]){
MnemonicTest mnemonicTest=new MnemonicTest();
}
}
One of these menuitems has the same mnemonic as the menu itself.
When I press Alt-(this same mnemonic), normally it must open the menu so I can
choose the menuitem myself. But unfortunatly, it sends directly the action related to the menuitem having this mnemonic, without opening the menu. Which is completely incoherent.
The problem is seen in Java 1.2.2-005, but not in Java 1.3.0-C where is works
correctly
Test case:
I sent you a example that shows the problem.
After launching the example, see the menuitems in the menubar.
Then try to type Alt-F, it opens directly a JOptionPane telling that the FROM
menuitem has been fired. Normally, it must open then File menu without firing anything.
-----
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MnemonicTest{
JFrame frame;
public MnemonicTest(){
frame=new JFrame();
JLabel label=new JLabel("Testing");
frame.getContentPane().add(label);
JMenuBar menuBar=new JMenuBar();
MenuActionListener menuActionListener=new MenuActionListener();
JMenu fileMenu=new JMenu("File");
fileMenu.setMnemonic('F');
JMenu editMenu=new JMenu("Edit");
editMenu.setMnemonic('E');
JMenuItem toMenuItem=new JMenuItem("To");
toMenuItem.setMnemonic('t');
toMenuItem.addActionListener(menuActionListener);
JMenuItem fromMenuItem=new JMenuItem("From");
fromMenuItem.setMnemonic('f');
fromMenuItem.addActionListener(menuActionListener);
fileMenu.add(toMenuItem);
fileMenu.add(fromMenuItem);
JMenuItem viewMenuItem=new JMenuItem("View");
viewMenuItem.addActionListener(menuActionListener);
viewMenuItem.setMnemonic('v');
editMenu.add(viewMenuItem);
menuBar.add(fileMenu);
menuBar.add(editMenu);
frame.setJMenuBar(menuBar);
frame.setSize(new Dimension(200, 200));
frame.setVisible(true);
}
public class MenuActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(frame, "Selected MenuItem is "+e.getActionCommand());
frame.repaint();
}
}
public static void main(String args[]){
MnemonicTest mnemonicTest=new MnemonicTest();
}
}
- duplicates
-
JDK-4213634 Alt+menmonic char not working when menu & menuitem have same mnemonic char.
-
- Closed
-