I need to remove all items from the combo box
int itemCount = combo.getItemCount();
for(int i=0;i
You can use
this.combo.removeAllItems();
to remove all the items in JComboBox.
In second line:
combo.removeItemAt(0)
;
I think instead of 0
it should be i
.
do it in reverse order as:
for(int i=combo.getItemCount()-1;i>=0;i--){
combo.removeItemAt(i);
}
But in my case combo.removeAllItems()
works fine
The code in the question would normally work. However, it looks like a threading issue. Another thread may be messing with the items.
However, I sugeest you should better use the removeAllItems();
method:
combo.removeAllItems();