select - How to store the JComboBox item in 2 variables? -


i have jcombo box populated hashmap(each jcombobox item equal hashmap object - formatted 2 values:one key , 1 value). when use getselecteditem() - return : key=value ;

i need store key in 1 variable , value in variable .

how can this? there exist alternarive jcombobox store 2 values each item of jcombobox ?

as got question. here simple jcombobox class. can understand process reading code , modify wish

import java.util.arraylist; import java.util.map; import javax.swing.defaultcomboboxmodel; import javax.swing.jcombobox;  public class jcomboboxpair<k, e> extends jcombobox<e> {  private arraylist<object> key_array;  public jcomboboxpair() {     this.key_array = new arraylist<>(); }  public void setmodel(map<string, string> map) {     defaultcomboboxmodel boxmodel = new defaultcomboboxmodel(map.values().toarray());     super.setmodel(boxmodel);     key_array.clear();     key_array = new arraylist<>(map.keyset()); }  public string[] getselectediteminfoarray() {     string[] ar = new string[2];     ar[0] = key_array.get(super.getselectedindex()).tostring();     ar[1] = super.getselecteditem().tostring();     return ar; }  @override public string getselecteditem() {     return super.getselecteditem().tostring(); }  public string getselectedkey() {     return key_array.get(super.getselectedindex()).tostring(); }  } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -