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

Adding items to JComboBox is extremely slow

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.0
    • 1.2.1
    • client-libs
    • beta
    • x86
    • windows_nt



      Name: dbT83986 Date: 04/29/99


      Adding items to JComboBox after it is initialized is extremely
      slow. We have one window with two tabs and few Labels, text
      fields and combo boxes on both tabs. It was taking almost 3
      minutes after we invoke from our application main window. After
      running this in OptimizeIt, I noticed out of 174 seconds total
      time, 171 seconds are taken in addItem method. The combo box
      has 697 items. Combo boxes with less items are ok. It generates
      fireIntervalAdded everytime and need to recalculate bounds every
      time new item added. In this case we have workaround to pass
      vector in the constructor instead of later adding each item, but
      in some cases we get a vector by some other action on window.In
      that case we need to call addItem for all the items in the vector.
      It is serious performance concern in some of the windows in our
      application.

      I have created a small test program to prove this. I am creating
      one frame and adding combo box to it. I am adding 500 elements
      to combo box. It takes 110 seconds to bring up this small window.
      (out of 110 seconds, 108 seconds are taken by addItem method.

      Here is the java source for the example
      ------------------------------------------------------------
      package comboTest;

      import java.awt.*;
      import javax.swing.*;
      public class Frame1 extends JFrame {
          JComboBox jComboBox1 = new JComboBox();

          public Frame1() {
              try {
                  jbInit();
              }
              catch(Exception e) {
                  e.printStackTrace();
              }
          }

          public static void main(String[] args) {
              Frame1 frame11 = new Frame1();
              frame11.setSize(300, 200);
              frame11.show();
          }

          private void jbInit() throws Exception {
              // Adding 500 elements here
              for(int i = 0 ; i < 500; i++)
                  jComboBox1.addItem(new Integer(i));
              this.getContentPane().add(jComboBox1, BorderLayout.NORTH);
          }
      }
      ---------------------------------------------------------------
      (Review ID: 57655)
      ======================================================================

            tsantossunw Tom Santos (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: