Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4484334

JMenuItem.setMnemonic() does not work properly in 1.4beta

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs



      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)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: