• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JComboBox and ArrayList

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesnt solve the problem though
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic