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

SortingFocusTraversalPolicy performs redundant sort during traversal

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
    • CPU:
      generic
    • OS:
      generic

      Description

      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);
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ant Anton Tarasov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: