| Author |
JComboBox and ArrayList
|
Thomas Richards
Greenhorn
Joined: Mar 20, 2005
Posts: 7
|
|
Ok so i have an ArrayList and i want to populate a JComboBox with its contents. I know i could do the following... String [] arrayCats = theGame.categorys.toArray (new String[ theGame.categorys.size () ]); However this isnt working! I have changed my code to declare the new JComboBox in the constructor (where im creating the GUI etc). Help! I cant progress any more without being able to do this eek! Thanks in advance
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Just to narrow down the problem a bit, if you did the following: Does it work?
|
 |
Thomas Richards
Greenhorn
Joined: Mar 20, 2005
Posts: 7
|
|
|
Yep if i add b to the form then gregg and thomas are displayed in the box.
|
 |
Thomas Richards
Greenhorn
Joined: Mar 20, 2005
Posts: 7
|
|
That doesnt solve the problem though
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
So my guess is that something isn't working with the following: theGame.categorys.toArray (new String[ theGame.categorys.size () ]); What are categorys? And shouldn't it be categories? What if instead of using the toArray method you iterated over the categorys and put them in a new array?
|
 |
Thomas Richards
Greenhorn
Joined: Mar 20, 2005
Posts: 7
|
|
The categories ( ) is a container if you will, for some questions that fall into that category. The Categories are held in their own ArrayList and it all cascades down Categories list > Question List > Answer List. I shall try to itterate through the categories and putting them in a new array in the morning. (I live in the UK so im tired after a full day of this). Thanks for your help i shall be posting again tommorow
|
 |
 |
|
|
subject: JComboBox and ArrayList
|
|
|