File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
jQuery in Action, 2nd edition
 
subject: JComboBox and ArrayList