5
I have a JComboBox
which allows selecting only the first item clicked, in case I want to change selection it does not allow.
In the jPanel
There are two other combos that are identical with the one that has the behavior explained, but they work perfectly, in case I wanted to change item is allowed.
I already created a test but the behavior persists.
Can anyone tell me what it might be?
final JComboBox comboBoxBem = new JComboBox();
comboBoxBem.setToolTipText("Descri\u00E7\u00E3o do Bem");
comboBoxBem.setForeground(new Color(0, 0, 0));
comboBoxBem.setFont(new Font("Tahoma", Font.BOLD, 11));
comboBoxBem.setBounds(365, 314, 402, 20);
comboBoxBem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (comboBoxBem.getSelectedItem() != null) {
try {
InformacoesDoBemBean informacoesDoBem;
if (comboBoxBem.getSelectedItem() != null &&
comboBoxBem.getSelectedItem() instanceof Bem) {
Bem bem = (Bem)comboBoxBem.getSelectedItem();
informacoesDoBem = controller.getInformacoesDoBem(bem.getCodigo(),
bem.getPatrimonio());
if (informacoesDoBem != null) {
textFieldNumeroDoBem.setText(informacoesDoBem.getCodigo());
textFieldResponsavelPelaArea.setText(informacoesDoBem.getNomeResponsavel());
textFieldPatrimonio.setText(informacoesDoBem.getPatrimonio());
textPanelDescricao.setText("");
lblValorCaractRestante.setText("80");
}
}
} catch(Exception ex) {
logger.error("####ERRO AO OBTER INFORMAÇÕES DO BEM: ", ex);
JOptionPane.showMessageDialog(container,
"Ocorreu um erro ao carregar as informações do bem, tente novamente");
}
}
}
});
AutoCompleteDecorator.decorate(comboBoxBem);
container.add(comboBoxBem);
You have properly implemented the method
equals()
in classBem
?– utluiz
That’s right, it wasn’t implemented correctly. Thank you very much!
– adelmo00
Cool, I’ll add as an answer to make the question correct.
– utluiz