'how to make 3 combo boxes in java dependent on each other

for example, I want to make 3 combo boxes 1st one called destination 2nd one called Take off airport 3rd one called Arrival airport then if user choose destination : France, Take off airport :Cairo international so i want to make the only available choice of arrival airport is Lyon-Saint-Exupery also if user choose destination : France, Take off airport : Hurghada international airport i want to make the only available choice of arrival airport is Orly international airport



Solution 1:[1]

If I understood your question, then you want to if you select France in a JComboBox Then Other Boxes will show the airports in France? or only a single Airport? Is the answer looking like this? Just Add an itemlistener to the first combobox and add the items to the other comboboxes and make sure to remove all the items from the other two boxes while selecting from the first combobox

Box1.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent arg0) {
            if(Box1.getSelectedItem().equals("France")){
                Box2.removeAllItems();
                Box2.addItem("Cairo");
            }
        }
    });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1