Loading an ArrayList into a JCombobox using netbeans

孤者浪人 提交于 2019-12-02 10:48:05

You could create your own ComboBoxModel that takes a List as the main parameter, but that's a little more involved

comboboxSunday.setModel(new DefaultComboBoxModel());
for (Object item : listOfItems) {
    comboboxSunday.addItem(item);
}

Assuming your array looks something like this:

String[] SundayList = { "Activity1", "Activity2", "Activity3", "Activity4" };

You can do this:

javax.swing.JComboBox sundayCombo = new javax.swing.JComboBox(SundayList);

If your array isn't a string array. try:

javax.swing.JComboBox sundayCombo = new javax.swing.JComboBox(SundayList.toString());

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!