Focus doesn't go into focus traversal policy provider when it's focusable

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 7
    • Affects Version/s: 6
    • Component/s: client-libs
    • None
    • b21
    • generic
    • generic

      Considering the following hierarchy of components:

      frame[ comp1 container[ comp2 comp3 ] comp4 ]

      where <frame> is the parent of <comp1>, <container> and <comp4>
      and <container> is the parent of <comp2> and <comp3>.

      <frame> has ContainerFocusTraversalPolicy.

      In such a case the cycle of traversable components looks as follows:

      <frame> -> <comp1> -> <container> -> <comp2> -> <comp3> -> <comp4>.

      However, if we make <container> focus traversal policy provider,
      the cycle changes in the following way:

      <frame> -> <comp1> -> <container>.

      I.e. a) focus doesn't go into the provider,
           b) focus jumps over <comp4>.

      In DefaultFocusTraversalPolicy, the same problems are revealed
      when making <container> focusable.

      Swing's policies (SortingFTP and LayoutFTP) also follows the
      behaviour pointed by (a), with <container> set focusable.

      This behaviour is considered illogical. The content of the provider
      is unreachable in forward traversing. The behaviour in this case
      shouldn't be different from the behaviour of a simple container.

      Below is the testcase:

      ================================
      import java.awt.*;
      import java.awt.event.*;

      public class AWTPolicy {
          
          public static void main(String[] args) {
              final Frame f = new Frame("Frame");
              final Panel p = new Panel();
              Button b0 = new Button("comp1");
              Button b1 = new Button("comp2");
              Button b2 = new Button("comp3");
              Button b3 = new Button("comp4");

              f.setFocusTraversalPolicy(new ContainerOrderFocusTraversalPolicy());
              f.addFocusListener(new FocusAdapter() {
                      public void focusGained(FocusEvent e) {
                          System.err.println("Frame got focus.");
                      }
                  });

              if (args.length > 0 && "provider".equals(args[0])) {
                  p.setFocusTraversalPolicyProvider(true);
              }

              p.addFocusListener(new FocusListener() {
                      public void focusGained(FocusEvent e) {
                          p.setBackground(Color.red);
                          System.err.println("Panel got focus.");
                      }
                      public void focusLost(FocusEvent e) {
                          p.setBackground(Color.gray);
                      }
                  });
              p.setBackground(Color.gray);

              f.add(b0);
              p.add(b1);
              p.add(b2);
              f.add(p);
              f.add(b3);

              f.setLayout(new FlowLayout());
              f.pack();
              f.setVisible(true);
          }
      }
      ==================================

      Run the test and try to forward traverse focus though the whole cycle.
      Then run the test with "provider" argument and find the cycle changed.

            Assignee:
            Anton Tarasov (Inactive)
            Reporter:
            Anton Tarasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: