i have following Problem, I add some Objects to a ComboBox. In the GUI i see now the objectsname and the ID. Is it possible to display instead a Attribute value of this object per Example the attribute name. You cant really identify the object over the ID.
Now its "Class@73dds676d7" and i want to show a name like "Apple juice"
The "id" actually is the hashcode. What you are seeing is the return value of the toString method of the objects, which they probably inherited from java.lang.Object.
So one solution would be to override the toString method. Problem is that you might want to have a different representation for the same objects in other places.
A more flexible approach is to set a custom ListCellRenderer on the combobox.
Moving to our Swing forum...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
posted 11 years ago
How can i do that?
i have no idea how i could write this code. I would write in my gui class where the combo box is following method