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

Layout-/SortingFocusTraversalPolicy vs. invisible FocusTraversalPolicyProviders

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • client-libs
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.6.0-beta2"
      Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
      Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux mokoscha 2.6.13-15.10-default #1 Fri May 12 16:27:12 UTC 2006 i686 i686 i386 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      When the components in scope of a Layout-/SortingFocusTraversalPolicy contain a *invisible* Container that isFocusTraversalPolicyProvider(), traversal breaks at the component, that is, getComponentBefore/getComponentAfter return 'null' instead of just skipping the non-showing components.
      ('null' is returned because typically non-showing Components are not accepted for traversal by FocusTraversalPolicy).

      The problem occurs because, on the one hand, invisible FocusTraversalPolicy providers, unlike normal Containers, are added to the cycle of Components that is then sorted (SortingFocusTraversalPolicy.enumerateCycle) and used as candidates.

      On the other hand, the results of calls to the provider's policy are returned directly (in four places), instead of continuing with the next candidate if such a call yields 'null' (here, because there is no showing component in that subtree). This is also a problem in a more general context.

      Although other potentially invisible Containers are also added to the cycle list (focus cycle roots, JComponents with isManagingFocus), this problem only occurs for FocusTraversalPolicy providers.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute code and press TAB (or shift-TAB) repeatedly.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All visible buttons should be reachable by pressing TAB (or shift-TAB) repeatedly.
      ACTUAL -
      Only the buttons preceding the invisible one are reachable by pressing TAB.

      By pressing shift-TAB, the buttons following the invisible one and the first are reachable.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;


      public class SortingVisibleBug
      {
          public static void main(String[] args)
          {
              final JFrame f = new JFrame();

              f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.PAGE_AXIS));

              final JButton[] buttons = new JButton[7];

              for (int i = 0; i < buttons.length; i++)
              {
                  buttons[i] = new JButton(String.valueOf((char)('A' + i)));
                  f.getContentPane().add(buttons[i]);
              }


              // Middle button is FocusTraversalPolicy provider and invisible

              int index = buttons.length / 2;

              buttons[index].setFocusTraversalPolicyProvider(true);
              buttons[index].setVisible(false);


              f.setBounds(200, 200, 600, 400);
              f.setVisible(true);
          }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Write your own FocusTraversalPolicy.

            ant Anton Tarasov (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: