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

SortingFocusTraversalPolicy performs redundant sort during traversal

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9
    • client-libs
    • generic
    • generic

      The problem is that if I traverse across a container with SortingFocusTraversalPolicy, that policy builds a traversal sequence from scratch (by sorting the container order of components) on every focus transfer, even when the hierarchy of components doesn't change.

      This is practically insensible in an average form, but with a huge number of components it becomes perceptible for the user. The focus transfer lag can be reproduced with the following test case where 5.000 buttons are added to a frame at random location. Run the test and try to Tab across the buttons.

      import java.util.Random;
      import javax.swing.JButton;
      import javax.swing.JFrame;

      public class SortTest {
          static final int COUNT = 5000;
          static final int SIZE = 30;
          static final int WIDTH = 1024;
          static final int HEIGHT = 768;
              
          public static void main(String[] args) {
              JFrame f = new JFrame("frame");
              f.setLayout(null);
              f.setSize(WIDTH, HEIGHT);
              Random r = new Random();
              for (int i = 0; i < COUNT; i++) {
                  JButton b = new JButton("" + i);
                  b.setBounds(r.nextInt(WIDTH - SIZE), r.nextInt(HEIGHT - SIZE), SIZE, SIZE);
                  f.add(b);
              }
              f.setVisible(true);
          }
      }

            Unassigned Unassigned
            ant Anton Tarasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: