I have two swing combo boxes. We will call the first one parent, and the second one dependant. When the dialog box is drawn, a search in a database is performed to get the correct Object (depends on the user and what the user has saved to date), for the parent JCombobox. What I want is, when the user changes their selection in the parent JCombobox, that the program searches the database and delivers the correct Object for the dependent. Short of making the user decide which parent choice he wants before the primary dialog is opened, how do I go about writing the code to update the dependent JCombobox when the parent is changed?
You start with adding an ActionListener to the parent combo box. This will be triggered when a new value is selected. If this occurs, you need to find the Object for the parent combo box' current selected (getSelectedItem()). A Map<Object,Object> is the easiest way to perform this lookup. Next you either update the existing model for the dependent combo box, or create a new ComboBoxModel for the new content and set that model.
That error message was just my stupidity. I forget to say that a is a certain object and not null. I now have an object in the JCombobox, but the object is the array, and not the contents of the array. Is it possible to add an array after the JCombobox is made?
I ended up using a foreach loop to add each object in the object array seperately. I find it dumb that you cannot just add the whole array, or at least if you can, i didnt figure it out, but this works. Thank you all for your help.