TAGS :Viewed: 10 - Published at: a few seconds ago

[ Retrieving text from a combobox that has been bound to a database table ]

I have created a jCombobox that is bound to a database table. I have modified the renderer code to display the field properly, in this case a persons surname. However when I try and retrieve the selected text from the combobox using jComboBox1.getSelectedValue().asString, I get the sort of text that would have been displayed if I had not modified the renderer code. e.g. "combotest.Staff[ staffId=M2653101 ]" How do I retrieve the text as it is displayed?

Answer 1


You have a getRenderer() method in JComboBox, but the cleanest solution would be to move the transformation from the renderer code to a static method somewhere (or even better to the toString() of your object), and then call this method from the renderer, and also from the other place.