Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding ID to JComboBox

Posted on 2006-06-23
19
Medium Priority
?
454 Views
Last Modified: 2008-03-03
Hello there,

I´ve got a problem with the JComboBox! I get a List of items, which I add to a JComboBox but I´m only able to add the "TEXT" to it. But I also have to add a ID, which identifies the Text, to the ComboBox. Do you have any Solution for my problem??

Thanks a lot for your help!

Greetings
Markus
0
Comment
Question by:mfAudi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
  • +1
19 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16968819
The ComboBoxModel holds Object. You can make an object with those fields. Make its toString retrun what you want and it#'ll be displayed
0
 

Author Comment

by:mfAudi
ID: 16968908
Can you show me a little Example??

THX
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 195 total points
ID: 16969076
Just add instances of this class to your model:

public class MyData {
      private int id;
      private String text;

      public void setId(int id) {
            this.id = id;
      }

      public int getId() {
            return id;
      }

      public void setText(String text) {
            this.text = text;
      }

      public String getText() {
            return text;
      }
      
      public String toString() {
            return text;
      }

}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 180 total points
ID: 16969107
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16969172
mfAudi can you tell me why my answers were ignored?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16969218
This should have been a split.
0
 

Author Comment

by:mfAudi
ID: 16969220
I don´t know! I accepted your last answer! And I also rated it as "GOOD"!

Why are you asking??

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16969226
You accepted my answer, not CEHJ's.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16969229
>>I accepted your last answer!

No you didn't - you accepted *someone else's* answer ;-)
0
 

Author Comment

by:mfAudi
ID: 16969272
I´m sorry, so did I! But both answers were similar in quality!

Sorry CEHJ! Next time. I was to much in a hurry cause I have to solve a problem at my workingplace!

Have a nice WE!

CU
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16969294
>>But both answers were similar in quality!

I have to beg to differ and that's no disrespect to mayank. His link, while useful, does not deal directly with your specific problem
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16969317
Ah, so CEHJ takes the name finally in his 9 years at EE ;-)

mfAudi, if the sample code on the link which I posted helped you and if that was the one you used, then you should split the points between CEHJ and me because he had also posted a similar code earlier.

I'll ask Venabili to re-open.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16969338
:-)
0
 

Author Comment

by:mfAudi
ID: 16969387
OK, no Problem! Both of you helped me very much!

But no I finisch working and I will do it on monday!

Hasta la vista!

Greetings from good old Germany! (SOCCER-World-Championship-2006) ;-)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16969395
:-)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16969982
>> Both of you helped me very much!

mfAudi, you can now follow the Split Points link which you see below (and above the comment box) to split points between CEHJ and me.
0
 
LVL 92

Expert Comment

by:objects
ID: 16973287
> Greetings from good old Germany! (SOCCER-World-Championship-2006) ;-)

Go the socceroos :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16981687
:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question