Tag Archives: jcombobox

JComboBox Key – Value Pair

8 Jul

To create JComboBox with key and value first create next class:

public class myItemS {

    public String key, value;

    KorakItem(String key_, String value_) {
        key = key_;
        value = value_;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return value;
    }
}

After that you can use this class in the following way:

// cmbMyCMB is already created object @JCombobox
cmbMyCMB.addItem(new myItemS('0','JAVA'));
cmbMyCMB.addItem(new myItemS('1','C#'));
cmbMyCMB.addItem(new myItemS('2','PHP'));