Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox and ArrayList

 
Kevin Magee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm having problems filling a JComboBox with the
contents of an ArrayList.
The JComboBox is not appearing onscreen. I'm
using JPanel, and all other components are displayed except the combobox. This is my first time using swing, so any help would be greatly
appreciated.

 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really use swing. But I believe becuse of the hierarchy, you have to add a Jcombo box/Jlist to a frame, and then set the size and show the frame. I stand corrected though...
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a simple example showing how to do this.
 
Kevin Magee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
The code I had given was already a part of a program using JPanel and JFrame. I was just not sure of way JComboBoxes work, especially with
ArrayLists or Vectors.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you notice you do not have to extract what you want in the box, just create a toString() for your class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic