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

WindowsTabbedPaneUI overrides focus traversal keys

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      Compile version:

      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

      Runtime Version:

      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Windows XP using the Windows Look and Feel

      A DESCRIPTION OF THE PROBLEM :
      In WindowsTabbedPaneUI, the following code appears:

      protected void installDefaults() {
              super.installDefaults();
      contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque");

              // focus forward traversal key
              if (managingFocusForwardTraversalKeys==null) {
                  managingFocusForwardTraversalKeys = new TreeSet();
                  managingFocusForwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
              }
              tabPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, managingFocusForwardTraversalKeys);
              // focus backward traversal key
              if (managingFocusBackwardTraversalKeys==null) {
                  managingFocusBackwardTraversalKeys = new TreeSet();
                  managingFocusBackwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
              }
              tabPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, managingFocusBackwardTraversalKeys);
          }

      As you can see, it forces a certain set of tab traversal keys. This means that any components placed in a tab pane will only allow traversal via TAB and Shift-TAB, which seems totally wrong, and counter-productive to the setDefaultFocusTraversalKeys method of KeyboardFocusManager. This means that if an application needs to make app-wide changes to the focus traversal keys, it pretty much can't on Windows.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a basic swing app
      2. In the main method, set the default focus traversal keys for FOCUS_FORWARD_KEYS to a set containing TAB and Control-X
      3. Create a JTabbedPane
      4. Create a JPanel and put it in the JTabbedPane
      5. Put two text fields in the JPanel
      6. Run the application
      7. Select the first text field.
      8. Hit TAB. Focus travels normally
      9. Select the first text field again.
      10. Hit Control-X. Nothing happens, because the focus traversal keys have been undone by the JTabbedPane

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect that if the JTabbedPane needed to ensure that tab and shift-tab worked, it should simply get the default set and add them.

      Furthermore, if the JTabbedPane needed to avoid specific keys, it should copy the default set, remove them, and make THAT set it's focus traversal keys.

      Overriding what the programmer has specified just seems wrong.
      ACTUAL -
      Focus traversal key settings are undone by the JTabbedPane

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      The workaround is to create a subclass of WindowsTabbedPaneUI that overrides the installDefaults method to set the tab traversal keys to null, so that the defaults get used.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: