How to set selected index JComboBox by value
I want to set the selected index in a JComboBox by the value not the index. How to do that? Example public class ComboItem { private String value; private String label; public ComboItem(String value, String label) { this.value = value; this.label = label; } public String getValue() { return this.value; } public String getLabel() { return this.label; } @Override public String toString() { return label; } } JComboBox test = new JComboBox(); test.addItem(new ComboItem(0, "orange")); test.addItem(new ComboItem(1, "pear")); test.addItem(new ComboItem(2, "apple")); test.addItem(new ComboItem(3,