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

Strange behavior of JMenuBar with RIGHT_TO_LEFT orientation, arrow keys behaves opposite traversing through keyboard

    XMLWordPrintable

Details

    • b12
    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      After applying setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT) to the JMenuBar the arrow keys started to behave the opposite of what expected. Right arrow goes left and Left arrow goes right when trying to traverse through keyboard. Note that I'm using Native look and feel.

      Here is the code:

      import java.awt.BorderLayout;
      import java.awt.ComponentOrientation;
      import java.awt.Dimension;
      import java.awt.Toolkit;

      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;

      @SuppressWarnings("serial")
      public class MenuBarProblem extends JFrame {
              
          private JMenuBar menuBar;
          
          private JMenu firstMenu;
          private JMenuItem a;
          private JMenuItem b;
          
          private JMenu secondMenu;
          private JMenuItem c;
          private JMenuItem d;
          
          private JMenu thirdMenu;
          private JMenuItem e;
          private JMenuItem f;
          
          public MenuBarProblem() {
              this.setLayout(new BorderLayout());
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              this.setExtendedState(JFrame.MAXIMIZED_BOTH);
              this.setSize(screenSize);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              
              this.firstMenu = new JMenu("first");
              this.a = new JMenuItem("a");
              this.b = new JMenuItem("b");
              this.firstMenu.add(this.a);
              this.firstMenu.add(this.b);
              
              this.secondMenu = new JMenu("second");
              this.c = new JMenuItem("c");
              this.d = new JMenuItem("d");
              this.secondMenu.add(this.c);
              this.secondMenu.add(this.d);
              
              this.thirdMenu = new JMenu("third");
              this.e = new JMenuItem("e");
              this.f = new JMenuItem("f");
              this.thirdMenu.add(this.e);
              this.thirdMenu.add(this.f);
              
              this.menuBar = new JMenuBar();
              this.menuBar.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); //Here is the reason
              this.menuBar.add(this.firstMenu);
              this.menuBar.add(this.secondMenu);
              this.menuBar.add(this.thirdMenu);
              this.setJMenuBar(this.menuBar);
          }

      }


      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              psadhukhan Prasanta Sadhukhan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: