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

Unable to navigate through JRadioButton/JButton using keyboard mnemonic when components have same mnemonic

XMLWordPrintable

      Unable to navigate through JRadioButton/JButton using keyboard mnemonic when components have same mnemonic

      OPERATING SYSTEM(S):
      Windows XP
      Possibly on Linux as well

      FULL JDK VERSION(S):

      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode)

      DESCRIPTION:

      Not able to navigate through all the available buttons/radio buttons when more than one button/radio buttons have same mnemonic.

      Steps to recreate
      -----------------

      1. Compile and run the below testcase using the above specified java
      2. You can see 3 radio buttons have the same mnemonic keys assigned (ALT+y)
      3. Try to navigate through the radio buttons by pressing "ALT+y" combinations
      4. The focus always transferred to the last radio button and never navigate through the other radio buttons.

      Expected behavior: You should be able to navigate through all the components which supports that mnemonic. For example, when clicking "alt+y" first time, focus should be transferred to first radio button, next time second radio button and so on.

      import javax.swing.*;
      import java.awt.event.*;
      import java.awt.*;

      public class JRadioButtonTest extends JFrame{

      JRadioButtonTest() {
      final int numButtons = 4;
      JRadioButton[] radioButtons = new JRadioButton[numButtons];
      final ButtonGroup group = new ButtonGroup();

      final String defaultMessageCommand = "default";
      final String yesNoCommand = "yesno";
      final String yeahNahCommand = "yeahnah";
      final String yncCommand = "ync";

      radioButtons[0] = new JRadioButton("OK (in the L&F's words)");
      radioButtons[0].setActionCommand(defaultMessageCommand);
      radioButtons[0].setMnemonic(KeyEvent.VK_O);

      radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)");
      radioButtons[1].setActionCommand(yesNoCommand);
      radioButtons[1].setMnemonic(KeyEvent.VK_Y);

      radioButtons[2] = new JRadioButton("Yes/No "
      + "(in the programmer's words)");
      radioButtons[2].setActionCommand(yeahNahCommand);
      radioButtons[2].setMnemonic(KeyEvent.VK_Y);

      radioButtons[3] = new JRadioButton("Yes/No/Cancel "
      + "(in the programmer's words)");
      radioButtons[3].setActionCommand(yncCommand);
      radioButtons[3].setMnemonic(KeyEvent.VK_Y);

      for (int i = 0; i < numButtons; i++) {
      group.add(radioButtons[i]);
      }

      radioButtons[0].setSelected(true);
      this.setLayout(new FlowLayout());
      for(int i=0;i<numButtons;i++) {
      this.getContentPane().add(radioButtons[i]);
      }

      this.setVisible(true);
      this.setSize(800,400);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
      public static void main(String arg[]) {
      new JRadioButtonTest();
      }
      }


      The same issue can be seen with JButtons, JCheckBox etc.

      I think the cause for the problem is how the mnemonics are handled in the KeyboardManager to fireKeyboardAction.

            Unassigned Unassigned
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: