I am populating a combobox using a DefaultComboBoxModel and a custom Item. Each item contains an id and a name. I am iterating through a table, and based on a selection, I would like to remove selected elements from the combobox. For the items I want to remove, I have the ID and Name from the table I am iterating through. I have tried using removeItem which takes in an object. I pass the ID and Name into my custom Item constructor, but that does not seem to work. Can anyone tell me what I am missing here?
Code for populating combobox:
Vector<Object> companyList = new Vector<Object>();
while(rs.next()){
companyList.addElement(new Item(rs.getInt(1),rs.getString(2)));
}
DefaultComboBoxModel cmod = new DefaultComboBoxModel(companyList);
companyName.setModel(cmod);
Code for custom Item:
class Item
{
private int id;
private String name;
public Item(int id, String name)
{
this.id = id;
this.name = name;
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
public String toString()
{
return name;
}
}
Code for removing Item (hard-coded for this example):
companyName.removeItem(new Item(50002,"ALLIED WASTE SYSTEMS"));
removeItem says it takes in an Object so I am not sure why this won't work. Any help would be appreciated!