This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have researched the Java Ranch forum for Swing/... and don't see
an entry quite like this. There was one other but it had no code.
My intent is to have two combo boxes - pickRstrInit and pickRstrName.
The first combo box selects the initial of last name.
This causes the data base to be read for all persons whose last name
begins with that initial. And load those names into the second combo box.
Then the second combo box is selected to cause the record of that name to
In the code below, the first combo box is initialized with a letter array.
The second is initialized with a #.
Two switches are used to indicate which box has been selected.
chrPickSwt1 is set for the initial combo box and chrPickSwt2 for the name
When the initial combo box has been selected, the code does what it should
in that it reads the data table and does pickRstrName.addItem which adds the
data record to the second box. At the end of the data base code, I put code
to delete the # record.
The problem is that the deletion statement pickRstrName.removeItemAt(0)
cause an Action Event "comboBoxChanged" which prematurely does processing
before a name is selected, causing a null pointer exception.
Is this the best way to do this? Or is there a method I am not
familiar with that is better? Any advice would be helpful.
not sure what the problem is, and I can't run the code to see what's happening,
but, generally the best way to 'load' the second comboBox (after selection of item in first comboBox)
is to change the model, combo2.setModel(..)
if there's a problem in the second comboBox listener firing when a change is made to the contents of the comboBox,
remove the listener, make the change, add the listener back.