我设置了一个jcombobox和actionlistener,填充了combbox,我选择了下拉名称,并且getSelectedItem保持返回null作为值:
ContactComboBox.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
ContactComboBox = (JComboBox) e.getSource();
if ("comboBoxChanged".equals(e.getActionCommand())) {
final Employee primary = (Employee) ContactComboBox.getSelectedItem();
LOG.debug("Getting current contains for primary combobox {} ", primary);
if (primary != null) {
primary.setPrimaryContact(true);
for (Employee emp : getEmployeeListCopy()) {
if (!emp.equals(primary)) {
primary.setPrimaryContact(false);
}
}
}
}
}
});