Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox and ArrayList

 
Thomas Richards
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to narrow down the problem a bit, if you did the following:



Does it work?
 
Thomas Richards
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep if i add b to the form then gregg and thomas are displayed in the box.
 
Thomas Richards
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesnt solve the problem though
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic