Se possível eu gostaria de uma breve explicação de como funcionariam estes eventos dos ComboBox;
O Exemplo é o seguinte:
ComboBox1 é carregado com uma série de estados por exemplo;
ComboBox2 é carregado com uma série de cidades conforme o selectedItem do ComboBox1;
ai eu queria que quando alterasse o selectedItem do ComboBox1(estados) o ComboBox2(cidades) re-executasse o método que ele tem, que faz a busca pelas cidades conforme o selectedIitem do ComboBox1(estados).
valeu ai pessoal, já procurei na internet encontrei um exemplo só não conseguir fazer funcionar neste meu exemplo para 2 ComboBox, eu não entendi onde colocaria o método que eu já tenho, o exemplo está aqui:
[code]// Create component
String[] items = {“item1”, “item2”};
JComboBox cb = new JComboBox(items);
cb.setEditable(true);
// Create and register listener
MyActionListener actionListener = new MyActionListener();
cb.addActionListener(actionListener);
class MyActionListener implements ActionListener {
// Retain the previously selected item in order to determine whether
// the new item is the same
Object oldItem;
// This method is called whenever the user or program changes the selected item.
// Note: The new item may be the same as the previous item.
public void actionPerformed(ActionEvent evt) {
JComboBox cb = (JComboBox)evt.getSource();
// Get the new item
Object newItem = cb.getSelectedItem();
// Determine if different from previously selected item
boolean same = newItem.equals(oldItem);
oldItem = newItem;
if ("comboBoxEdited".equals(evt.getActionCommand())) {
// User has typed in a string; only possible with an editable combobox
} else if ("comboBoxChanged".equals(evt.getActionCommand())) {
// User has selected an item; it may be the same item
}
}
}
[/code]
brigadão