File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Combo box madness Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Combo box madness" Watch "Combo box madness" New topic

Combo box madness

Ramzi Hajaj

Joined: Aug 19, 2012
Posts: 13
I am trying work a combobox with an array of objects. Im passing the in the combobox constructor but its coming up with what i think is the address of the object within the elements of the array. Is there anyway to get it to printout the local variables within each objects?

here is code:

returnplayers() returns an array of player objects. I just want to displaye their names instead of "Domain.Player@2f729e" which is what i am getting atm in the combobox.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

What you are seeing there is the result of calling the toString() method of the Player object. Since you haven't provided an implementation of that method, you get the default implementation provided by the Object class.

So implement a toString() method in your Player class and have it return whatever you want to see in that combo box.
Ramzi Hajaj

Joined: Aug 19, 2012
Posts: 13
That is sick! Cheers man will sort this madness out.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
Careful what you write. There are people all over the world here, and many will misunderstand things like “That is sick!” and madness.
I agree. Here's the link:
subject: Combo box madness
It's not a secret anymore!