-
Bug
-
Resolution: Fixed
-
P4
-
1.2.1
-
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)
======================================================================