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.
So it finds a ResultSet (rs), and populates the JComboBox with addresses; if I enter my own postcode I see several addresses from this street. And they change colour if I click them, but I can only seem to get it to return the first Address in the Vector. The System.out.printf call never seems to be executed. I have tried changing to new JComboBox(addresses.toArray()) and myAddress = addresses.get(addressBox.getSelectedIndex()); and commented the two lines starting // out and commented them back in, but it resolutely selects the first address in the street. It looks very like the example in my copy of Deitel and Deitel (6th edition page 544) and similar to the examples in the Java Tutorial, so I can't see what I have done wrong. I even tried commenting out the ItemListener and replacing it with an addActionListener call, but no change.
What have I done wrong? [ October 09, 2008: Message edited by: Campbell Ritchie ]
Originally posted by Michael Dunn: can you hard-code 5 or 6 address (lieu of rs.next()), and post a compilable program?
Yes, but it will be a couple of hours before I post it. I tried with an ActionListener and got a test printout but it always read 0. I shall have a look at the link later.
Joined: Oct 13, 2005
Thank you very much; when I saw Dunn and Prime were on the case I knew I was onto a winner.That is a simplified version of what I was running. It seems to be the setEditable(false) which helped, as Rob said. I have had a look at Michael's previous link and seen how that works.
Thank you very much, both of you
I am still having problems, however. This simple version reliably prints out 11 High St or 13 High St, but I am still having problems with my complicated version. I am going to try with a stand-alone version with its own database connection which might be easier to analyse.