I want to get the items of a combobox, and store it in an ArrayList object.
+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
2009-11-25 13:00:44
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
2009-11-25 13:38:01
I believe OP was referring to all the items in the combobox?
TStamper
2009-11-25 14:03:24
Sometimes OP isn't very clear on what she really wants ;)
Andreas_D
2009-11-25 14:19:52
true, thats why I put a '?' at the end of my comment
TStamper
2009-11-25 14:25:24
Aren't we all ... believers? ;-)
Andreas_D
2009-11-25 14:27:10