java - How to link two Jlists -


i have 2 jlists of vectors filled data extracted mysql db. want when user select item (menu) jlist1 (which called menulist) jlist2 (which called productlist) must display products of menu , other things, such ability insert new product in menu or in new menu created. i've accomplished task in way think weak, using boolean variables tells if user inserting product in existing menu or in newly created one. please, can suggest me better solution (if exists)? here extract of significant part of code, method saves new product in db:

private void baddprodactionperformed(java.awt.event.actionevent evt) {                                              //if new menu saved, new menu's id      if (newmenuissaved == true) {         product newproduct = new product();         newmenuid = dbconnection.getnewmenuid();         newproduct.setmenuid(newmenuid);         newproduct.setproductname(productname.gettext());         if (checkppricevalidity(productprice.gettext(), newproduct)) {             int result = dbconnection.insertproduct(newproduct);             if (result == 1) {                 reloadproductlist();                  disableproductbuttons();             }         }      } else {         product newproduct = new product();         //if new menu wasn't saved, menuid selected 1 (from menulist):         menu selectedmenu = (menu) menulist.getselectedvalue();         newproduct.setmenuid(selectedmenu.getmenuid());         newproduct.setproductname(productname.gettext());         if (checkppricevalidity(productprice.gettext(), newproduct)) {             int result = dbconnection.insertproduct(newproduct);             if (result == 1) {                 reloadproductlist();                 newmenuissaved = false;                 disableproductbuttons();                 bnewproduct.setenabled(true);              }         }     } }                                         

and here method reloadproductlist():

private void reloadproductlist() {     modelproductlist.clear();      if (newmenuissaved) {         vector<product> productvoices = dbconnection.fillproductlist(newmenuid);         (int = 0; < productvoices.size(); i++) {             modelproductlist.addelement((product) productvoices.get(i));         }     } else {         vector<product> productvoices = dbconnection.fillproductlist(selectedmenuid);         (int = 0; < productvoices.size(); i++) {             modelproductlist.addelement((product) productvoices.get(i));         }      } } 

thank much.

one way add listselectionlistener menulist , have handler set other list's model display details selected row.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -