JDK-4243181 : DefaultFocusManager very slow when lots of components
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-06-02
  • Updated: 2001-07-18
  • Resolved: 2001-07-18
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
EVALUATION The description contains a good evaluation. Name: keR10081 Date: 07/18/2001 This bug is no longer reproducible after focus putback, since that putback has removed buble sort code and now mergesort from Collections.sort() is used. ======================================================================
2004-06-11

WORK AROUND Name: clC74495 Date: 06/02/99 Manage your own focus in containers with lots of children. ======================================================================
2004-06-11