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

[macosx] swing shortcuts are counterintuitive with non-english keyboard layouts

    Details

      Description

      FULL PRODUCT VERSION :
      java version " 1.7.0_40-ea "
      Java(TM) SE Runtime Environment (build 1.7.0_40-ea-b28)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b47, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Model Name:Mac mini
        Model Identifier:Macmini6,2
        Processor Name:Intel Core i7
        Processor Speed:2.3 GHz
        Number of Processors:1
        Total Number of Cores:4
        L2 Cache (per Core):256 KB
        L3 Cache:6 MB
        Memory:16 GB

      A DESCRIPTION OF THE PROBLEM :
      At least, on Mac OS X usage of user shortcuts (JMenuItem.setAccelerator) is contra-intuitive with non-english keyboard layouts.

      User with a German or French keyboard should search through all keys to find the assigned shortcut. Text on the menu item is not corresponded to the actual keys.

        To illustrate the problem I have written the next manual test case. I am ready to write an automatic one if the issue will be considered as a bug.

      WINDOWS PLATFORM:
      On Windows toolkit the problem is less harmful. At least, KeyboardManager.fireKeyboardAction takes into account the extended key code. But If you try to assign a German symbol '??' (minus sign on the English keyboard), the KeyboardManager.fireKeyboardAction interprets it as an undefended symbol what is basically not true, taking into account that the e.getKeyChar() returns absolutely correct value - '??'.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Add a system layout (let's it be German)
          * On Mac OS X : System Preferences -> Language & Text -> Input Sources -> enable 'German' checkbox
      2. Run the code
      3. Turn on the English layout.
      4. Press ctrl-'-' on English keyboard
      5. Note that a text is printed in the console
      6. Switch layout to german one
      7. Press ctrl-'-' on English keyboard
      8. Note that a text is printed in the console
      9. Press ctrl-'/' on the English keyboard
      10. Note that a text is NOT printed in the console

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Steps 7 and 9 should be inverted. Because on german keyboard user does not see '-' on the key where it is placed on the english keyboard.
      ACTUAL -
      Shortcuts are associated with key codes not characters.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class LayoutInsensitiveManualTest {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      JFrame jFrame = new JFrame();
                      JMenuBar jMenuBar = new JMenuBar();
                      JMenu jMenu = new JMenu( " First menu " );
                      JMenuItem jMenuItem = new JMenuItem( " First menu item " );

                      jMenuItem.addActionListener(new ActionListener() {
                          @Override
                          public void actionPerformed(ActionEvent e) {
                              System.err.println( " Action performed on the menu item " );
                          }
                      });

                      // '-' is presented on German and English layout without pressing shift modifier key
                      jMenuItem.setAccelerator(KeyStroke.getKeyStroke('-', KeyEvent.CTRL_MASK));
                      jMenu.add(jMenuItem);
                      jMenuBar.add(jMenu);
                      jFrame.setJMenuBar(jMenuBar);
                      jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                      jFrame.setSize(200,200);
                      jFrame.setVisible(true);
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      It would be possible to workaround the issue if the javax.swing.KeyboardManager was not package private. By modifying KeyboardManager.fireKeyboardAction method

        Attachments

          Activity

            People

            • Assignee:
              sveerabhadra Shashidhara Veerabhadraiah
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: