tags:

views:

181

answers:

3

I want to get the items of a combobox, and store it in an ArrayList object.

+3  A: 

Have a look at Swing Tutorial: Combo Boxes.

extraneon
+1  A: 

I would suggest using the getItemCount to find out how many items are in the combobox then make a for loop using JComboBox's getItemAt to store the items in your created Arraylist using the Arraylist add()

TStamper
A: 

If you just need the selected items (most typical usecase), then just do

Object[] allSelectedAsArray = combobox.getSelectedObjects();
List<Object> allSelectedAsList = Arrays.asList(allSelectedAsArray);

Otherwise (maybe someone added a value to the combobox on the UI)

List<Object> allItemsAsList = new ArrayList<Object>();
for (int index = 0; index < combobox.getItemCount(); index++) {
  Object item = combobox.getItemAt(index);
  allItemsAsList.add(item);
}
Andreas_D
I believe OP was referring to all the items in the combobox?
TStamper
Sometimes OP isn't very clear on what she really wants ;)
Andreas_D
true, thats why I put a '?' at the end of my comment
TStamper
Aren't we all ... believers? ;-)
Andreas_D