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
You can use any Object as an item. In that object you can have several fields you need. In your case the value field. You have to override the toString() method to represent the text. In your case "item text". See the example:
public class AnyObject {
private String value;
private String text;
public AnyObject(String value, String text) {
this.value = value;
this.text = text;
}
...
@Override
public String toString() {
return text;
}
}
comboBox.addItem(new AnyObject("item_value", "item text"));