I've 3 comboboxes, upon selecting first combobox, the rest should be updated but my code doesn't seems to be working. Please help in this guys. Here is my code(since my code very long so I'll write error part only).
// example code
public class GuiComponents {
JComboBox<String> comboBox1, comboBox2, comboBox3;
public GuiComponents() {
.........
.........
String[] element1 = {"item1", "item2", "item3"};
String[] element2 = {"item1", "item2", item3};
String[] element3 = {"item1", "item2", "item3"};
comboBox1.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
if(event.getStateChange() == ItemEvent.SELECTED) {
// how do I update 2 comboboxes, upon selecting combobox1.
// combox2 should update as(element2) and
// combox3 should update as element3.
}
}
});
}
}
Thanks in advance....
If you intention is to change the combo box values when the user makes a selection, then you are better off using a
ActionListener
.If you want to the combo boxes to update each time the user selects a different item in the drop down list (and, yes, this is a different event), then you should use an
ItemListener
But in either case, the process is the same...