Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set items of a JComboBox with Array after initialization

843806Jun 5 2009 — edited Jun 6 2009
How can I set the items of a jcombobox as an array, after initialization (I mean not with the constructor) ?

Initially I use the default constructor that adds no items in the combobox:
comboBox = new JComboBox();
And then I'd like to set the items by passing an array
String a[]={"a","b"};
but the only method for doing this seems to be setModel(ComboBoxModel)

So when I try doing the following, the compiler shrieks:
comboBox.setModel(a);
Is there maybe a way to convert from a string array to a ComboBoxModel ?

Thanks very much.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2009
Added on Jun 5 2009
2 comments
8,264 views