JDK-4484334 : JMenuItem.setMnemonic() does not work properly in 1.4beta
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-07-25
  • Updated: 2001-07-25
  • Resolved: 2001-07-25
Related Reports
Duplicate :  
Description

Name: bsC130419			Date: 07/25/2001


java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

There are several issues with setMnemonic for JMenuItem. First of all, in
WindowsLookAndFeel, the character does not display as underlined UNLESS, the
menu is selected and then the mnemonic for the menu item is typed. Then the
underline will appear and IFF the menu is already open, the mnemonic appears to
work.

In Windows or Metal look and feel, the mnemonic does not work unless the menu
is already open. (So JMenu mnemonics appear to not work).

Run the following code and type "Alt+F". Notice that nothing happens. Then
select the menu item and type "Alt+F" or "Alt+X". Notice that the exit menu is
then selected.



/**
 * Title:        basis<p>
 * Description:  Your description<p>
 * Copyright:    Copyright (c) 1999<p>
 * Company:      Basis<p>
 * @author Kshanti Greene
 * @version
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;
import java.awt.print.*;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

public class WindowTest extends JFrame
{
    JLabel label;
    Font f;
    private int m_count;
    

    public WindowTest()
    {
        try
        {
            UIManager.setLookAndFeel(new WindowsLookAndFeel());
        }catch(Exception e){}
        
        this.setSize(400,400);
        JMenuBar bar = new JMenuBar();
        JMenu menu = new JMenu("File");
        menu.setMnemonic('f');
        JMenuItem item = new JMenuItem("Exit");
        item.setMnemonic('x');
        item.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                System.err.println("menu item selected");
            }
        });
        menu.add(item);
        bar.add(menu);
        this.setJMenuBar(bar);
        
        setLocation(100,100);
        setVisible(true);
        
    }

    public static void main(String[] args)
    {
        WindowTest windowTest1 = new WindowTest();
    }
}
(Review ID: 128814) 
======================================================================

Comments
EVALUATION In Windows 2000 the menu items are hidden until you hit the the alt key, this is the behavior of the platform and thus we are mimicking it. The second problem is a lingering focus issue. No one has focus in this case, and thus the mnemonic isn't processed. Among others, this has been fixed as 4389332, so that if no one has focus the key bindings are still processed. scott.violet@eng 2001-07-25
25-07-2001