It's not a secret anymore!*
The moose likes Beginning Java and the fly likes JComboBox and ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JComboBox and ArrayList" Watch "JComboBox and ArrayList" New topic
Author

JComboBox and ArrayList

Kevin Magee
Greenhorn

Joined: Feb 02, 2002
Posts: 18
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

Joined: Nov 06, 2000
Posts: 1510
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...


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Here is a simple example showing how to do this.
Kevin Magee
Greenhorn

Joined: Feb 02, 2002
Posts: 18
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

Joined: May 17, 2001
Posts: 2823
If you notice you do not have to extract what you want in the box, just create a toString() for your class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JComboBox and ArrayList
 
Similar Threads
how to store datecombobox in an arraylist of type combobox
JTable selected row problem
Redrawing a JComboBox
JComboBox Action Issues.
Using a JComboBox to change the contents of another JComboBox