JComboBox:ActionListener设置但getSelectedItem返回null

时间:2011-06-09 11:39:59

标签: swing combobox nullpointerexception jcombobox actionlistener

我设置了一个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);
                        }
                    }
                }
            }
        }
    });

0 个答案:

没有答案