aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JComboBox and ArrayList 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 and ArrayList" Watch "JComboBox and ArrayList" New topic
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Just to narrow down the problem a bit, if you did the following:



Does it work?


GenRocket - Experts at Building Test Data
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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
 
jQuery in Action, 2nd edition
 
subject: JComboBox and ArrayList