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

Menu's accelerator key propagates to textfields

XMLWordPrintable

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



      Name: mf23781 Date: 07/27/98


      Run the test case Driver below and then follow the instructions:

      import com.sun.java.swing.*;
      import java.awt.event.*;
      import java.awt.*;

      public class Driver extends JFrame
      {

      JMenuBar menuBar = null;
      JMenu fileMenu = null;
      JMenuItem logonMenuItem = null;
      JMenuItem exitMenuItem = null;
      JFrame frame = null;

      public static void main(String[] args)
      {
      new Driver();
      }

      public Driver()
      {
      super();

      createMenu();
      addEvents();

      setBounds(50,50,200,200);
      setVisible(true);

      frame = this;
      }

      public void createMenu()
      {
      menuBar = new JMenuBar();

      fileMenu = new JMenu("File");
      fileMenu.setMnemonic((int)'F');

      logonMenuItem = new JMenuItem("Logon");
      logonMenuItem.setMnemonic((int)'L');

      exitMenuItem = new JMenuItem("Exit");
      exitMenuItem.setMnemonic((int)'x');

      fileMenu.add(logonMenuItem);
      fileMenu.addSeparator();
      fileMenu.add(exitMenuItem);

      menuBar.add(fileMenu);
      setJMenuBar(menuBar);
      }

      public void addEvents()
      {
      exitMenuItem.addActionListener
      (
      new ActionListener()
      {
      public void actionPerformed(ActionEvent ae)
      {
      System.exit(0);
      }
      }
      );

      logonMenuItem.addActionListener
      (
      new ActionListener()
      {
      public void actionPerformed(ActionEvent ae)
      {
      MyDialog md = new MyDialog(frame);
      }
      }
      );
      }

      }

      class MyDialog extends JDialog
      {
      JLabel label = null;
      JTextField text = null;

      MyDialog(JFrame f)
      {
      super(f);
      getContentPane().setLayout(new FlowLayout());
      label = new JLabel("Label");
      text = new JTextField(10);
      getContentPane().add(label);
      getContentPane().add(text);

      pack();
      setVisible(true);
      text.requestFocus();
      }
      }

      Press <ALT>+F to expand File menu, press L key to activate
      Logon menuitem.

      Our logon dialog box (2 JLabels / 2 JTextfields) appears
      with the letter 'L' in the first text field.
      It appears as if the key event is not being consumed properly.

      This occurs on Swing 1.0.2 and Swing 1.0.3
      ======================================================================

            gsaab Georges Saab
            miflemi Mick Fleming
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: