|
First, you need to use JDBC to read the fields from your database. Do this only once, unless the fields in the database are constantly changing. I assume you are creating a Swing UI or something similar, so that's normally pretty easy. For Web apps, that have to generate the combo box over and over, create a separate class to read the fields and store them in a list. Use a static method to retrieve the list. This way, many classes on many threads can use the list.
As far as striping the entries, in Swing, that's beyond my abilities. The problem is that JComboBox accepts a list of objects and uses something like toString() to get the values it displays. When you ask the component what is selected, it returns the object, which is very helpful. However, the implementation does not appear to provide a means of controlling how the lines are produced. Look at ComboBoxUI if you like.
|