问题描述
当前有一个名为 SundayList 的ArrayList,它会在加载框架 AddStudent (GUI位)后立即加载
Currently have an ArrayList called SundayList which is loaded as soon as the frame AddStudent is loaded (bit of GUI)
Netbeans自动生成的代码是:
The code automatically generated by Netbeans is:
comboboxSunday = new javax.swing.JComboBox();
comboboxSunday.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item1", "Item2" }));
如何使用自己的数组加载组合框项目?该数组包含以下项目:
How do I load the combobox items with my own array?The array includes items such as:
Activity1
Activity2
Activity3
Activity4
在我之前的搜索中,人们提到使用toString()
和toArray()
,并且我对这两种方法都不熟悉,以及它们如何帮助将列表加载到组合框中,因为我是Java的新手. ..
From my previous search, people mentioned about using a toString()
and toArray()
, and I'm not familiar with either methods, and how they help in loading the list into the combobox as I'm quite new to java..
推荐答案
您可以创建自己的ComboBoxModel
,该ComboBoxModel
以List
作为主要参数,但是要涉及更多
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);
}
这篇关于使用NetBeans将ArrayList加载到JCombobox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!