I'm working on a program on which 2 JComboBoxes must set each other's selected item. Let's dub their object names wheelsTypeCombo and carBrandCombo. Both of their models contain each a list of objects retrieved from a database(objects of type 1 in the first list and objects of type 2 in the second list)and also a special wheelsTypeShowAll and respectively carBrandShowAll of the corresponding types. When either of the last 2 items are selected then all the containing items in both JComboBoxes are shown including themselves(the 2 special items).
The rules of the JComboBoxes reciprocal relation are as follows:
- when we select an item from wheelsTypeCombo, the carBrandCombo is reloaded with all the car brands that use that ONLY those types of tires and the carBrandShowAll item
- when carBrandShowAll item is selected from the 1st situation state of carBrandCombo then the carBrandCombo is reloaded with all the corresponding items from the database, also the wheelsTypeCombo has the selected item wheelsTypeShowAll .
- when we select an item from carBrandCombo then the corresponding wheels type item is selected in the wheelsTypeCombo
- if items that are already in a corresponding relation are selected then no setSelectedItem action is required by either of the JComboBoxes
Momentarily i tried using anonymous ItemListener classes, when I add the JComboBoxes to the interface, but found myself battling stack and null pointer exceptions overflows caused by inter calling method calls probably.
I would appreciate any kind of reasonable improvements on any level.