java - Display selected Item in JComboBox when item is clicked -


i have 2 jcomboboxes. when item in first jcombobox selected, relevant items displayed in jcombobox2. when try select items in second jcombobox keeps returning default. registering value of item selected, not displaying selected item in jcombobox.

here snippet of code:

maincombobox = new jcombobox( treeitems);     maincombobox.addactionlistener( );       getcontentpane().add( maincombobox, borderlayout.west );      //  create sub combo box multiple models      subcombobox = new jcombobox();     subcombobox.addactionlistener(this);       subcombobox.setprototypedisplayvalue("xxxxxxxxxx"); // jdk1.4     getcontentpane().add( subcombobox, borderlayout.east );      string [] chromalveolataitems = chromalveolatatreeset.toarray(new string[chromalveolatatreeset.size()]);     subitems.put(treeitems[1], chromalveolataitems);      string [] mycetozoaitems = mycetozoatreeset.toarray(new string[mycetozoatreeset.size()]);     subitems.put(treeitems[2], mycetozoaitems);      string [] metazoaitems = metazoatreeset.toarray(new string[metazoatreeset.size()]);     subitems.put(treeitems[3], metazoaitems);      string [] viridiplantaeitems = viridiplantaetreeset.toarray(new string[viridiplantaetreeset.size()]);     subitems.put(treeitems[4], viridiplantaeitems);      string [] virusesitems = virusestreeset.toarray(new string[virusestreeset.size()]);     subitems.put(treeitems[5], virusesitems); 

.

@override public void actionperformed(actionevent e) {     string item = (string)maincombobox.getselecteditem();     object o = subitems.get( item );     string organismcomboitem = (string)subcombobox.getselecteditem();     if(treearray.contains(organismcomboitem)){                  //system.out.println(treearray.indexof(organismcomboitem));        string selectedid = idarray.get(treearray.indexof(organismcomboitem));        system.out.println(selectedid);               }      if (o == null)     {         subcombobox.setmodel( new defaultcomboboxmodel() );     }      else     {         subcombobox.setmodel( new defaultcomboboxmodel( (string[])o ) );      } } 

there relatively simple solution new java please forgive me.

any whatsoever appreciated! :)

looks me based code on example found in posting: binding comboboxes in swing (or 1 it).

when use examples don't add code.

subcombobox.addactionlistener(this); 

the example not this. adding same listener subcombobox telling reset every time select item it. maincombobox needs actionlistener.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -