java - JComboBox ActionListener not working after removeAllItems() was used -


i have 2 jcomboboxes; 1 removes items in other if it's populated , adds new set of items, , second fires event gets information database using selected item. problem occurs after first combo box thing removing items , adding new ones; when select of items in second jcombobox, event fires doesn't happen anymore.

below have provided snippets of code:

the first combo box

    cmbids.addactionlistener(new actionlistener()     {         public void actionperformed(actionevent e)         {             selection = (string)cmbids.getselecteditem();             if (!(selection.equals("select username")))//current selection in combobox stored string             {                 comboactivate(selection);                 if (!unitc.gettext().equals("")){                     unitc.settext("");                 }                 if (!lecturer.gettext().equals("")){                     lecturer.settext("");                 }                  if (!(coursed.gettext().equals("not enrolled"))){                         populateunits(selection);                 }              }             else{                 joptionpane.showmessagedialog(null,"please select surname.");             }         }     }); 

removing items inside populateunits(string selectionid):

    try      {         units.removeallitems();         units.additem("select unit");     }     catch (nullpointerexception npe)     {         units.additem("select unit");      } 

after instructions sent through client server db queried , server replies information added second jcombobox. assure items added jcombobox after removeallitems() used.

the second jcombobox:

units.addactionlistener(new actionlistener() {     public void actionperformed(actionevent ue)     {         uselect = (string)units.getselecteditem();         if (!(uselect.equals("select unit")))//current selection in combobox stored string         {             system.out.println(uselect);             unitactivate(uselect);         }         else         {             joptionpane.showmessagedialog(null,"please select unit.");         }     } }); 

it looks code never gets fresh set of items database, user can never select other "select unit", second code block ignores.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -