Guys, Im having trouble working with Jcombobox.

I have this action listener in Jcombox that would get the ID of the current selected item which is a query from my db.

here's my simple code:

//clientName is the variable I declare for my JCombobox. 

private void clientNameActionPerformed(java.awt.event.ActionEvent evt) {
       //db connection code here
       rs = statement.executeQuery(" SELECT clientname FROM clientTbl ");
       while(rs.next()){
           clientName.addItem(rs.getString("clientname"));
       }
       String str = (String) clientName.getSelectedItem();
       System.out.print(str);
}

I dont have problems showing all clientname in the combobox, what im stuck with is, evry time I select a value from the combobox nothing happens. only the first value that has been queried will be the output after selected. any suggestions guys?

String str = myCombo.getSelectedItem.toString()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.