This week's book giveaway is in the Performance forum. We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line! See this thread for details.
Hi all, My first post in more than half a year or so... :-)
I am working on a new Swing application. I encoutner a problem which should be trivial but keeps on bothering me... :-( In my object model, I have a property (The datatype of some published content) which can have a few discrete values, therefore I declared it as an int property and defined some constants for it. For each row in the JTable, the user must be able to select a value for this property, i use a JCombobox for this purpose. Of course, the user does not want to see the value of the integer contant, but a readable description. To achieve this, I defined a ComboBoxEntry class holding both the id (int value) and the description of the item, the toString method is overrided to return the description. Because JComboBox uses the toString method to render its values, I can add ComboBoxEntry instances to it, which are then displayed as descriptions.
To render the particular JTable column as a combobox, I set it as the renderer for this column:
In the setValueAt method of the TableModel, I write the selected value backto the object model as follows:
This works. But when the value is not edited in the table, it is still displayed as a number. I know that I must add an appropriate renderer, but do not know how to read the string value of the selected item...
To summarize, I want to edit a numeric property as a lookup field in my table, and render it as a string. This seems to be a trivial and often needed fucntionality to me, but the implementation gives me a headache... Any tips ??? TIA, Klaas
"What you don't know, can't help you"
SCJP (81%), SCWCD (81%), SCJD (354/400), SCBCD (85%)