PDA

View Full Version : Java Swing Problem


guyshahar
Jul 4, 2006, 01:35 AM
A JComboBox has constructors that can take a Vector or a ComboBoxModel.

When I pass a DefaultComboBoxModel to it, and change the contents of the DefaultComboBoxModel, the drop-down list changes as expected. No problem.

However, if I pass a Vector to it and change the contents of the Vector, the drop-down list goes blank. It is still there, because if I click on any point in the blank space, the most recent option is called and the list is then visible.

I have tried calling validate() on the JComboBox, but it makes no difference.

I want to experiment with generics, and cannot do so with DefaultComboBoxModel. Can anybody tell me a simple way to use Vectors in Swing without weird results??

LTheobald
Jul 5, 2006, 01:12 AM
I missed this one yesterday. I'll try and recreate the problem myself some time today.

In the meanwhile let me know what JDK you are using in case that makes a difference.

guyshahar
Jul 5, 2006, 01:29 AM
Thanks. It's the 5.0 JDK for Windows.

Somebody proposed a solution to me that seems to work. They told me that having updated the Vector, I need to add the line:

ComboBox.setModel(new DefaultComboBoxModel(vector));

And this updates the drop-down list.

Strange that without this line, the list updates eventually, but is initially blank...