I use a combo box on panel and as I know we can add items with the text only
comboBox.addItem(\'item text\');
But some times I need to
create a new class called ComboKeyValue.java
public class ComboKeyValue {
private String key;
private String value;
public ComboKeyValue(String key, String value) {
this.key = key;
this.value = value;
}
@Override
public String toString(){
return key;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
}
when you want to add a new item, just write the code as below
DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement(new ComboKeyValue("key", "value"));
properties.setModel(model);