Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4349795
Votes 0
Synopsis Same mnemonic letter on a JMenu and a JMenuItem don't work correctly
Category java:classes_swing
Reported Against 1.2.2_005
Release Fixed
State 11-Closed, duplicate of 4213634, bug
Priority: 2-High
Related Bugs 4213634
Submit Date 30-JUN-2000
Description
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();
    }
}
Work Around
None
Evaluation
N/A
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang