🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12868

Re: JComboBox addItem poor performance

#12868
From: Mikael Lindkvist
Date: Wed, 28 Oct 1998 00:00
34 lines
1673 bytes
The code in the example is slow because each call to addItem results in
events being fired and several method calls in the underlaying datamodel.

You should instead use the vector as an argument when you construct the
combo (the JComboBox(Vector) constructor for example) or design your own
ComboBoxModel and then use this model instead of the default model that is
constructed for you when using the JComboBox() constructor.

/Mikael Lindkvist



Nigel Fletton wrote:

> Any ideas on why the addItem call in the example code below is very slow
> when rebuilding the content of a JComboBox?
>
> The vector typically contains around 50 Strings. On the application this
> code sample comes from, there are several similar combo boxes on a
> tabbed form that result in the form being very slow to rebuild when new
> data is loaded.
>
>     Vector v;
>     .......
>     String strExample;
>     combo.removeAllItems();
>
>     e = v.elements();
>     while(e.hasMoreElements()) {
>       strExample = e.nextElement().toString();
>       combo.addItem(strCompItem);
>    }
>
> Nigel
Technical Details
Message-ID: <3636C476.71F5B3AE@infodata.sema.se>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3635DEFB.9C533C93@bt.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,f8cf4a252f41cfb9
X-Google-Attributes: gid111d45,public
From: Mikael Lindkvist <mikael.lindkvist@infodata.sema.se>
Subject: Re: JComboBox addItem poor performance
Date: 1998/10/28
Message-ID: <3636C476.71F5B3AE@infodata.sema.se>
X-Deja-AN: 405848556
Content-Transfer-Encoding: 7bit
References: <3635DEFB.9C533C93@bt.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing