wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox" Watch "JComboBox" New topic


joe tran

Joined: Aug 25, 2004
Posts: 7
I have an array of objects called procedures. These objects have the attribute int code which I'd like for the JComboBox to display. But instead it displays some other information, such as the directory where these objects were imported from. How do I get it to display only a certain part of the objects in the array that I populate the JComboBox with? Thanks in advance to anyone with an answer.

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, joe!

I'm moving this to the Swing / AWT / SWT / JFace forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Try this

Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

The way I do this is to over ride the toString() method in the "Procedure" class.

since you say the procedure object is kicking out directory information or something, it may already have a toString() defined

that returns something like:

public String toString(){
return this.attribute1 + " : " + this.attribute2

if it already has one defined, you would have to make a method with a new name or overload the toString method.

public String toString(String type){
return this.attribute1 + ": " + this.attribute2;


toString() is called automatically for display when you stick an object into a combo box
I agree. Here's the link: http://aspose.com/file-tools
subject: JComboBox
jQuery in Action, 3rd edition