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

DefaultFocusManager very slow when lots of components

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.1
    • client-libs



      Name: clC74495 Date: 06/02/99


      (This is in Swing 1.1.1beta2, but applies to all versions)
      The DefaultFocusManager is extremely slow when a container has many children. A testcase is given below.

      The finger-of-blame goes to DefaultFocusManager.childrenTabOrder(), which uses a bubble sort[!!]. Replacing the bubble sort with a quick sort made the code about twenty times faster with the below (admittedly, extreme, but not entirely unrealistic) test case.

      import java.awt.*;
      import javax.swing.*;

      public class FocusTest extends JPanel
      {
        static public void main(String[] args)
        {
          JFrame frame = new JFrame();
          frame.setContentPane(new FocusTest());
          frame.pack();
          frame.setVisible(true);
        }

        private FocusTest()
        {
          setLayout(new GridLayout(30, 30));
          for (int i = 0; i < 900; i++)
          {
            add(new JTextField("Field", 5));
          }
        }
      }
      (Review ID: 83175)
      ======================================================================

            joutwatesunw Joshua Outwater (Inactive)
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: