JDK-4382796 : RFE: Performance of JComboBox with DefaultComboBoxModel (re-open 4138101?)
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,windows_95
  • CPU: generic,x86
  • Submitted: 2000-10-25
  • Updated: 2013-11-01
  • Resolved: 2001-11-14
Related Reports
Duplicate :  
Duplicate :  
Description

Name: yyT116575			Date: 10/25/2000


orig synopsis:  "Horrible performance of JComboBox with DefaultComboBoxModel"
see also # 4173836

java version "1.2.2"
Solaris VM (build Solaris_JDK_1.2.2_05a, native threads, sunwjit)


I'm sorry to resubmit a bug which is already in your database, but
I seriously think you should look at this one again.  It would take a
sun developer all of five minutes to fix, and it would improve performance
of JComboBox by SECONDS not just milliseconds.

Considering the bang for the buck, I simply can't believe this has gone
so long without being fixed.

Please reexamine bug 4138101.  The problem is that with a
DefaultComboBoxModel, there's no way to add a large group of items to
the model.  If you add them one at a time, with addElement(Object val),
then fireIntervalAdded() is called for each and every element you add,
which is VERY VERY slow.

I had a frame that contained a table.  Two of the columns in the table
had cell editors that were JComboBoxes, each with about 100 items in them.
Initially, I added the items to the JComboBoxes one at a time.  It took
my frame a whopping 15 - 17 seconds to come up!!!!  Almost unbelievable.
Then I simply changed the constructors of the JComboBoxes to take a vector
of the values, and the frame came up in about 3 seconds.

The problem I face is in a different part of the code where I MUST change the
list of values in the combo box after the combo box is constructed.  I
simply can't do it in a quick way.

PLEASE FIX THIS!  It's SOOOO easy to fix on your end and will improve
performance for lots and lots of your users.
(Review ID: 110650) 
======================================================================

Comments
WORK AROUND Name: yyT116575 Date: 10/25/2000 Write your own combo box model, instead of using DefaultComboBoxModel. But what a combersome work around for such a common problem. ======================================================================
11-06-2004

EVALUATION The performance bottleneck is from dynamically calculating the width of the popup based on the item. There are two solutions that you can try: 1. Add all the items to a ComboBoxModel and then add the combo box model to the combo box. This reduces all the messages that will be fired from addItem(..). 1. In 1.4, a new feature was introduced to specifify a prototype display value. This value represents the largest item in the combo box and eliminates the loop that iterates all the items searching for the widest item. See RFE 4289100. ###@###.### 2001-11-13
13-11-2001