I have been searching for an answer to this problem for months. I am converting a number of applications that were originally designed in MS Access to
Java Swing. I have everything resolved (including reporting - thanks to JasperReports!), except for this:
I need to have a JCombobox with more than one column. I have read other solutions that specify using a custom listcellrenderer, but I have not had luck with this. Could someone please post an example of this solution? Other posts usually have someone that asks "Why on earth would you need such an animal?" For those people, let me explain:
Above all, the reason usually boils down to the fact that my users need to have the fastest (most efficient) interface possible for user entry, while maintaining accuracy. These people beat on the keys all day long, and I can't afford to have unnecessary forms pop up for them to select certain items. To be as fast an efficient as possible, they occasionally need more than one column in a combobox. The reason a combobox is used instead of a table is for screen real estate. For example - the user is presented with a screen-filling form, with many components. This form accesses a database of information. One of the comboboxes represents the current job. This could be like 134, 645, etc� and this is what the user enters at this point, and then hits tab to move on. The problem is that while the user develops a sixth sense for entering job numbers, there are hundreds of jobs and we can't afford unnecessary mistakes. The user needs one column with the job number, and the next column to supply additional information, such as the job name, so that the user is confident that the correct job was entered. I usually make these comboboxes auto popup when focused. Also, this user must start and finish the form in just a few seconds, and the mouse is almost never touched.
In MS Access, this is very easy. You specify a query in the combobox to supply the columns of data in the combobox, and you select the column containing the bound value (the value of the actual selection). You also have additional control to hide certain columns, show or hide column headers, and to specify column widths.
The only thing that I could come up with in Swing that came close was to use a plain JCombobox, change the font to monospace, and pad the values with spaces to make my "columns" line up. I kept track of my "bound values" with methods to resolve the real value from the selected index. I was hoping for a better solution that would look like the rest of my form and have border lines between the columns. Auto-completion is also necessary, but I did find some code online for this that works with a normal JCombobox.
TIA for any help.