Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox

 
joe tran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Joe
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, joe!

I'm moving this to the Swing / AWT / SWT / JFace forum...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic