• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a non hard coded comboBox list  RSS feed

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to display a list of environment id's out of my xml file into a JComboBox. I don't want to hard code them in - is there any examples anyone could show me so I understand for the future please?
I understand fine how to make lists and what not but examples are always hard coded. If anyone could lend a hand I'd be pretty grateful - Alice.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are getting the IDs out of the file, you can add them to a List<ID>.

Beware. You may have to use the legacy class Vector<ID> rather than ArrayList because the JComboBox constructor doesn't accept a plain simple List<ID>.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's helpful thankyou but if my envionment ID's are sitting in the xml file - would I use the method I used before in my reader to iterate through the list?(see below)


 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes (at least I think so), but you only need <> after Vector if you use Java7+
You should have <String> after new JComboBox and <> between JComboBox and (myIdList).
If the nodeList reference points to a List there may be a simpler way to do it. Look at the constructors for Vector.
Do you really want your IDs to be plain Strings? Don't you have an ID class?
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have said environmentList instead of nodeList.
How are you getting the IDs out of the environment list? When I said nextID I presumed you had some way to get that particular reference. I can't see it in that code.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I put <> after JComboBox is tells me that it is not generic and cannot be parametrized with <>.

Should I remove the <> after Vector then as I don't think the pc I am using uses Java 7+.

I don't have an ID class just literally the xml file which contains:

[code=java]

<Environment id = "name">
//xml
</Environment>

I am using the environentList in my xlm reader.java file to iterate through the xml file and print them out to the console.

I left nextID in there as I had not changed it - I was trying to figure a way of retrieving said ID's.

If I'm using a SAXParser to do this - will this alter my current code?
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alice Hampton wrote:When I put <> after JComboBox is tells me that it is not generic and cannot be parametrized with <>.

Should I remove the <> after Vector then as I don't think the pc I am using uses Java 7+. . .
JComboBox most certainly is generic. Are you really using a version so old that it was before JComboBox became generic? If so, you should update your Java® installation. Java6 has officially been withdrawn. You should use Java8 if possible, otherwise the most recent version of Java7: It was Java7u67 yesterday.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.6.0_34 is, in English, Java 6 Update 34

Thats the version I have - it's not exactly the newest...
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 6, JComboBox is indeed not generic. JComboBox and JList were generified from Java 7.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is probably 5 years out of date. You should upgrade to 7u67 or 8u20 as soon as possible. Downloads pages here.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can tell it's not pc I'm using - mine are fully up to date. Thanks for the link
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Tell whoever the computer belongs to to update it.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
haha I think I will it's a lot more out of date than I thought!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!