Hi Everyone,
I'm trying to populate my jComboBox with the following items:
public class DropDownItem {
private String text;
private int id;
public void setText(String text) {
this.text = text;
}
public void setId(int id) {
this.id = id;
}
public String toString() {
return text;
}
public int getId() {
return id;
}
public boolean equals(Object i) {
System.out.println("i is: " + i);
if(i instanceof Integer) {
if((Integer)i == (Integer)id) {
System.out.println("It's me!");
return true;
}
else {
System.out.println("I was asked if I was " + (Integer)i + " but I'm " + id + " as I'm " + text);
return super.equals(i);
}
}
else return super.equals(i);
}
}
However I'm having trouble using jComboBox's setSelectedItem. I pass setSelectItem an int, and as you can see from above, I've tried to make sure that it gets selected when it's the correct one. The problem I'm having, is that only the currently selected item is checked, which to me is very strange. I verified that by added the print statement, which only gets printed out once..
Any ideas?
Thanks