Seleção JComboBox

4 respostas
rocha

Pessoal quero q qdo determinado item de um JComboBox seja selecionado execute determinada tarefa qual é o evento para isso?

4 Respostas

V

Coloca um exemplo do que vc quer fazer…

keller

ItemListener? :roll:

V

É isso?

private JComboBox getJComboBox() { String a[] = {"Primeiro","Segundo","Terceiro"}; if (jComboBox == null) { jComboBox = new JComboBox(a); jComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { JOptionPane.showMessageDialog(null,jComboBox.getSelectedItem()); } }); } return jComboBox; }

rocha

Resolvi assim:

private void jComboItemStateChanged(java.awt.event.ItemEvent evt) { // TODO add your handling code here: if (receptorEventos != null){ if(evt.getStateChange() == ItemEvent.SELECTED)//Verifica se algum intem está selecionado receptorEventos.executar(); } }

Criado 30 de maio de 2005
Ultima resposta 30 de mai. de 2005
Respostas 4
Participantes 4