Reputation: 97
I am trying to remove selected items in the JComboBox (I have added design time) But remove function is not executed. What am I doing wrong
// jComboBox1.removeAllItems(); working
// jComboBox1.removeItem(jComboBox1.getSelectedItem()); working
jComboBox1.remove(jComboBox1.getSelectedIndex()); not working
Upvotes: 2
Views: 4662
Reputation: 2886
From JavaDoc
public void remove(int index)
Removes the component, specified by index, from this container. This method also notifies the layout manager to remove the component from this container's layout via the removeLayoutComponent method.
Parameters:
index - the index of the component to be removed
But as mentioned in above answers you need to do
jComboBox1.removeItemAt(jComboBox1.getSelectedIndex());
Hope it helps
Upvotes: 1
Reputation: 96018
There is no such method remove
in Class JComboBox
.
You want to use public void removeItemAt(int anIndex):
Removes the item at anIndex This method works only if the JComboBox uses a mutable data model.
jComboBox1.removeItemAt(jComboBox1.getSelectedIndex());
Upvotes: 6
Reputation: 213
It looks like you want jComboBox1.removeItemAt(...)
see http://docs.oracle.com/javase/7/docs/api/javax/swing/JComboBox.html#removeItemAt(int)
Upvotes: 0