HP News Feed schrieb:
> I have seen various discussion entries about the poor performance of the
> JComboBox additem method when there are a large number of items in the
> control.
JComboBox just delegates the message down to its model. So the problem
has to be located there.
> The proposed route to improvement is invariably to use a
> DefaultComboBoxModel and then create the JComboBox control using the
> constructor that uses the Model. e.g.
Who proposed this? I'd suggest to not use DefaultComboBoxModel at all.
It uses Vector and Vector is slow due to synchronization.
> I support an application that is showing symptoms of this problem, and I
> have experimented with the above technique, and it appears to work well.
> However, I want to be able to re-populate the item list of an existing empty
> JComboBox i.e. I do not have the opportunity to invoke the model
> contstructor while creating a new JComboBox.
Use your own implementation of ComboBoxModel. Implement a method
setData, an add method that is able to add complete collections etc.,
then you don't need to create a new model object every time.
Bye
Michael
HP News Feed - 15 Jul 2005 13:56 GMT
> Who proposed this? I'd suggest to not use DefaultComboBoxModel at all. It
> uses Vector and Vector is slow due to synchronization.
The proposal came from here :
http://java.sun.com/features/2002/03/swinggui.html
I am not actually using a Vector - this just came from the example. Mine
uses a List. I will take a look at your suggestion of implementing my own
ComboBoxModel. I am still interested in the legitamy of my original
proposal though.
Thanks,
Steve.
> HP News Feed schrieb:
>> I have seen various discussion entries about the poor performance of the
[quoted text clipped - 23 lines]
> Bye
> Michael
Michael Rauscher - 18 Jul 2005 16:33 GMT
HP News Feed schrieb:
>>Who proposed this? I'd suggest to not use DefaultComboBoxModel at all. It
>>uses Vector and Vector is slow due to synchronization.
>
> The proposal came from here :
> http://java.sun.com/features/2002/03/swinggui.html
This is just an example. No one proposed to use a DefaultComboBoxModel.
The key statement is to "perform operations in bulk to reduce the number
of events that are posted". This is independent of the model class one uses.
The statemenent "construct a new one instead of reusing the existing
one" that is given in this paper is valid only for models that don't
have the ability to replace the contents - like DCBM. Have a look at
DefaultTableModel (which also uses Vector). There's a method
setDataVector where one can replace the whole table contents.
> I am not actually using a Vector - this just came from the example. Mine
> uses a List. I will take a look at your suggestion of implementing my own
If you use DCBM then you use a Vector as DCBM uses a Vector.
> ComboBoxModel. I am still interested in the legitamy of my original
> proposal though.
The setModel approach is correct. If the model can't replace data it's
the only correct way. Of course, the garbage collector will properly
take care of the fact that you create new objects all the time. You can
call box.setModel(null) in advance to release the old model. Loading
this way won't affect the dynamic behaviour.
Bye
Michael
Michael Rauscher - 18 Jul 2005 16:36 GMT
Michael Rauscher schrieb:
> You can
> call box.setModel(null) in advance to release the old model.
Delete this. Of course, you can't set the model to null...
> Bye
> Michael
Joan - 18 Jul 2005 21:37 GMT
> Michael Rauscher schrieb:
>
> > You can
> > call box.setModel(null) in advance to release the old model.
>
> Delete this. Of course, you can't set the model to null...
But you can set the Layout Manager to null <g>
Michael Rauscher - 19 Jul 2005 17:44 GMT
>>>You can
>>>call box.setModel(null) in advance to release the old model.
>>
>>Delete this. Of course, you can't set the model to null...
>
> But you can set the Layout Manager to null <g>
???
I wrote the above with respect to garbage collection.
Bye
Michael
Andrew Thompson - 19 Jul 2005 18:11 GMT
>>>>You can
>>>>call box.setModel(null) in advance to release the old model.
[quoted text clipped - 5 lines]
> ???
> I wrote the above with respect to garbage collection.
Hence the <g>.
I think that pun was more directed at folks that might
whine and complain every time someone sets a layout to
null, ..or about the quality of GUI advice delivered on
c.l.j.p.
Made me laugh!

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Beats A Hard Kick In The Face