java - JCombobox Listener how to enable it when item is selected? -


i have jcombobox displays name database patients_details

public void comboitem() {  chooser.removeallitems(); chooser.additem("please select..."); try {             string sql="select * patients_details";          pst = conn.preparestatement(sql);          rs=pst.executequery();         while (rs.next()) {             string id = rs.getstring("patient_id"); // id             string name = rs.getstring("name"); // name               comboitem comboitem = new comboitem(id, name); // create new comboitem             chooser.additem(comboitem); // put combobox             string tmp=comboitem.getid();         }     } catch (sqlexception sqle) {         system.out.println(sqle);     } } 

this comboitem class returns name , not id

  public string tostring() {     return this.name  ;    } 

my question how selecteditem action can performed have no clue how have been trying bunch of code 2 hours appreciated

nb java beginner

  private void chooserpopupmenuwillbecomeinvisible(javax.swing.event.popupmenuevent evt) {      try{       string sql="select * patients_details patient_id=? ";       pst=conn.preparestatement(sql);       rs=pst.executequery();       if(rs.next()){       string add1=rs.getstring("patient_id");       txtpatientid.settext(add1);       string add2=rs.getstring("name");       txtname.settext(add2);       string add3=rs.getstring("age");       txtage.settext(add3);       string add4=rs.getstring("gender");       txtgender.settext(add4);       string add5=rs.getstring("date");       txtdate.settext(add5);        }   }   catch(exception e) {     joptionpane.showmessagedialog(null,e );    } }   

simply add actionlistener combo box. when actionperformed called, can selected value , call ever methods need to

for example.

chooser.addactionlistener(new actionlistener() {     pubic void actionperformed(actionevent evt) {         object selectedvalue = chooser.getselectedvalue();         // carry on ever need     } }); 

have at...

for more details


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -