title: JCombobox Listener how to enable it when item is selected?
body: <p>I have a JComboBox that displays Name From database Patients_Details </p>
  
  <pre><code>public void ComboItem() {
  
  chooser.removeAllItems();
  chooser.addItem("Please Select...");
  try {   
           String sql="select * from Patients_Details";
           pst = conn.prepareStatement(sql);
           rs=pst.executeQuery();
          while (rs.next()) {
              String id = rs.getString("Patient_ID"); // Get the Id
              String name = rs.getString("Name"); // Get the Name 
  
              ComboItem comboItem = new ComboItem(id, name); // Create a new ComboItem
              chooser.addItem(comboItem); // Put it into the ComboBox
              String tmp=comboItem.getid();
          }
      } catch (SQLException sqle) {
          System.out.println(sqle);
      }
  }
  </code></pre>
  
  <p>This is from comboitem class that only returns the name and not the id</p>
  
  <pre><code>  public String toString() {
      return this.name  ;
     }
  </code></pre>
  
  <p>My question is how do I get the selecteditem so that this action can be performed I have no clue how to do this I have been trying all bunch of code for almost 2 hours
  any help will be much appreciated</p>
  
  <p>NB I am Java beginner</p>
  
  <pre><code>  private void chooserPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
  
      try{
        String sql="select * from Patients_Details where 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 ); 
    }
  }  
  </code></pre>