1
Someone would know to tell me some listener for when I select an item in Jcombobox it gives me a warning for example. Remembering that when I open my component(Jframe) I select items inside by the bank so I can’t fall into the Listener.
Let’s go explain my project better
The button "..." opens the mode registration window, every time I register a mode I updated the combo box "mode" that at the moment is with the record "dance" Every time I choose a mode in my combobox it will open a new window to register the monthly fee. So how do I load my combobox when I open my application without activating the Switch and how do I update the combobox without activating the Switch? I want Listener to be enabled only when the user selects an item from the list, but it looks like the "combobox.addItem("Test");" command activates the Listener when updating. Any suggestions?
Method used to update Combobox when I register a mode or when I just open my system.
public void setModalidade() {
try {
this.cboModalidade.removeAllItems();
this.listaModalidade = new ArrayList<Modalidade>(new ModalidadeDAO().listaTodos());
int i = 0;
for(Modalidade modalidade : listaModalidade) {
this.cboModalidade.addItem(modalidade.getTituloModalidade());
if(this.modalidade.getTituloModalidade().equalsIgnoreCase(modalidade.getTituloModalidade())) {
this.cboModalidade.setSelectedIndex(i);
}
i++;
}
} catch(SQLException e) {
e.printStackTrace();
}
}
These are the systems I use or have used to try.
JCombobox combobox = new JCombobox<>();
combobox.addActionListener(this); //<-- já tentei esse
combobox.addItemListener(this); //<-- Estou usando esse mas a função "combobox.addItem("Teste"); que utilizou para atualizar meu combobox ativa o ActionListener e o ItemListener
It was not clear to me, is there any particular item that should activate the warning? What does the database have to do with the Listener?
– Math
I believe your question is a little confused... Try to be clearer...
– Cristiano Pires
From what I understand, you want to put a Switch in an event that is triggered when the user selects an item from the combo. What you are now using to do this is being triggered when the method
addItem
it’s called. ls that it? It may be clearer if you enter the code for the Systener you are using, or at least indicate the name of the event you associated with the Systener.– dang
" What you are now using to do this is being triggered when the addItem method is called". That’s exactly what’s going on, I’m going to post the code to maybe improve understanding, but the program is already a bit complex, but come on
– Wilson Tamarozzi