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

Mnemonics not working when ALT key is released before character key

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.1, 1.4.2
    • client-libs
    • beta
    • x86
    • windows_2000, windows_xp

      Name: jk109818 Date: 01/02/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]


      A DESCRIPTION OF THE PROBLEM :
      JLabel.setLabelFor(JComponent) associated with
      setDisplayedMnemonic(char/int)is not working under certain
      circumstances.Say I am using 't' as a mnemonic key for a
      JTextField.When I press ALT+T key and if ALT is released
      before 't' then the focus is not going to the JTextField.It
      seems that the focus goes to the corresponding JLabel(not
      sure) because pressing tab takes the focus to the
      JTextField. But if 't' is released before ALT key or both
      ALT and 't' released simultaneously after pressing gives
      the correct behaviour - JTextField gets the focus.

      There was a bug similar to this(Bug# 4260595) Click here:
      http://developer.java.sun.com/developer/bugParade/bugs/42605
      95.html.But the state of the bug says "Closed, Fixed"(in
      kestrel - 1.3).Even then I am getting the same problem in
      the following versions of Java I tried.Hence opening a new
        Bug.


      1.3.0:
      ------
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build
      1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      1.3.1:
      ------
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build
      1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      1.4.1_01:
      ---------
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build
      1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      I am providing a test case below.Please check with that.

      Thanks,
      Jana

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.Press ALT + Mnemonic key (say 't').
      2.Release mnemonic key first or both keys simultaneously(No
      Problem).
      3.Release ALT key first and then the mnemonic key.
      JComponent doesnt get the focus.Pressing tab will take the
      focus to JComponent.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Releasing ALT key first and then the mnemonic key should
      take the focus to the JComponent.Its the general
      Accessibility etiquette.It works correctly with
      AbstractButton.setMnemonic('char/int').

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      JComponent not getting the focus.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.GridBagLayout;
      import java.awt.GridBagConstraints;
      import java.awt.Insets;

      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JLabel;
      import javax.swing.JTextField;
      import javax.swing.JButton;
      import javax.swing.JComboBox;
      import javax.swing.JPasswordField;

      public class JavaBug
      {
      public static void main(String args[])
      {
      JFrame fr = new JFrame("Bug");
      JPanel panel = new JPanel(new GridBagLayout());

      GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.gridy = GridBagConstraints.RELATIVE;
      gbc.gridwidth = 1;
      gbc.gridheight = 1;
      gbc.weightx = 0;
      gbc.weighty = 0;
      gbc.ipadx = 0;
      gbc.ipady = 0;
      gbc.insets = new Insets(5, 5, 5, 5);
      gbc.anchor = GridBagConstraints.NORTHWEST;
      gbc.fill = GridBagConstraints.NONE;

      JLabel label1 = new JLabel("Text:");
      panel.add(label1, gbc);

      JTextField jtf = new JTextField(20);
      label1.setDisplayedMnemonic('t');
      label1.setLabelFor(jtf);
      panel.add(jtf, gbc);

      JLabel label2 = new JLabel("Password:");
      panel.add(label2, gbc);

      JPasswordField pass = new JPasswordField(20);
      label2.setDisplayedMnemonic('p');
      label2.setLabelFor(pass);
      panel.add(pass, gbc);

      JLabel label3 = new JLabel("Items:");
      panel.add(label3, gbc);

      String items[] = {"One", "Two", "Three"};
      JComboBox combo = new JComboBox(items);
      label3.setDisplayedMnemonic('i');
      label3.setLabelFor(combo);
      panel.add(combo, gbc);

      JButton button = new JButton("Click");
      button.setMnemonic('c');
      panel.add(button, gbc);

      fr.getContentPane().add(panel);
      fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      fr.pack();
      fr.setVisible(true);
      }
      }
      ---------- END SOURCE ----------
      (Review ID: 179443)
      ======================================================================
      ###@###.### 10/13/04 17:52 GMT

            shickeysunw Shannon Hickey (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: