Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jcombobox not working when instantiated with comboboxmodel but works w

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
I instantiated my jcombobox with a comboboxmodel and i get the list of
names in the combo box but nothing happens when i select anyone of
them. But the same thing works when i instantiate the jcombobox with a
string array. everything works fine.
Any idea whats the problem with ComboBoxModel or any way to know the
problem source.

code follows:

ArrayList persons = someDAO.getAllNames();
final PersonListModel plm = new PersonListModel(persons);
final JComboBox personList = new JComboBox(plm);
personList.setEditable(true);

personList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String personName = (String)cb.getSelectedItem();
System.out.println("Name = " + personName);
}
});
 
Rather than an ActionListener, try using an ItemListener to detect when the state changes - itemStateChanged( java.awt.event.ItemEvent event ).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top