Title says it all.. Basically the program takes customer information and dumps it in a database. In order to change information I want the user to be able to pick a customer name from a combobox, so the system can then call all the info out of the database on that customer. Accessing the database is fine, putting info in and changing it is fine.. I just cant figure out how to get the combobox to populate with all the customer names.
The simplest solution is to create an array of String from the database. Then use that to create the combobox.
String[] mydbStrings = .....;
JComboBox mycombo = new JComboBox(mydbStrings);
But that will give you only some strings. It may be better to define a class that represents the customer, load the customers from the database, ensure that an adequate toString() is defined in the Customer class and create an array of Customers that is used in the Combo Box. That way, the customer names are displayed in the combobox but hwen you select one you have all the customer details readily available.
If you think this is too memory intensive to load all your customer's data at once it is possible to create a smaller custInfo class with just the name and ID. Then use that in the combobox and load the rest of the customer data after it is selected.
This should be simple if you know how to populate a normal combobox, and how to pull the data from the database. The combobox by default will take an array of strings in the constructor, so you could just pass an array of string(Customer names), but I would recommend creating a model for the combobox. You could then pass the Customers to the model(most likely some POJO's), and then you will also probably want to create a renderer so that you can display the names as you like. Then when a customer is selected you can query the model to get an id for the selected customer, and then use that to retrieve the needed customer data.