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

labelFor mnemonic does not work in some instances

XMLWordPrintable

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



      Name: rmT116609 Date: 08/05/2004


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

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If the mnemonic key is released before the ALT key, focus does not move to the combo box that is specified as the component for the labelFor property of a JLabel.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code given below. Select the ALT+C keyboard combination and release the ALT key before the C key. Focus will not move to the combo box. Try again, this time release the C before the ALT. In that case focus will move to the combo box.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Focus should move to the combo box regardless of whether the ALT key or the C key was released first.
      ACTUAL -
      Focus only moved to the combo box if the ALT key was released last.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;


      public class TestLabelForMnemonic
          extends JFrame
          implements ActionListener {
        JComboBox myComboBox;
        JLabel myLabel;
        JTextField myTextField;

        public TestLabelForMnemonic() {
          super("Test labelFor Mnemonic");
          myTextField = new JTextField("Text in textField");
          myComboBox = new JComboBox(
              new String[] {
              "First Row", "Second Row", "Third Row"});
          myLabel = new JLabel("Label for Combo Box");
          myLabel.setLabelFor(myComboBox);
          myLabel.setDisplayedMnemonic(java.awt.event.KeyEvent.VK_C);

          JPanel p = new JPanel();
          p.setLayout(new BorderLayout());
          p.add(myTextField, BorderLayout.WEST);
          myTextField.requestFocus();
          p.add(myLabel, BorderLayout.NORTH);
          p.add(myComboBox, BorderLayout.CENTER);
          setContentPane(p);
          pack();
        }

        public static void main(String[] args) {
          TestLabelForMnemonic testLabelForMnemonic1 = new TestLabelForMnemonic();
          testLabelForMnemonic1.setLocation(300, 300);
          testLabelForMnemonic1.setVisible(true);
        }

        public void setVisible(boolean willShow) {
          super.setVisible(willShow);
          myTextField.requestFocus();
        }

        public void actionPerformed(ActionEvent e) {
          System.out.println("event e = " + e);
        }

      }
      ---------- END SOURCE ----------


      (Incident Review ID: 214854)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: