我正在尝试在Netbeans中创建一个Swing GUI。我创建了一个jcombobox并将它(使用查询组件,列表组件和渲染器)绑定到名为' Item'的实体,以便组合框显示表中当前存在的项的名称"项目"到目前为止它工作正常。但是,我需要添加一个"所有项目"字段到组合框。有没有人对我应该从哪里开始有任何暗示?
答案 0 :(得分:1)
尝试
List<String> listItems = classDAO.findElement();
DefaultComboBoxModel<String> comboModel = new DefaultComboBoxModel();
for(String string : listItems)
{
comboModel.addElement(string);
}
comboModel.addElement("All items");
JComboBox<String> comboBox = new JComboBox<>(comboModel);
答案 1 :(得分:1)
您可以在将表格中的项目添加到组合框后手动将项目添加到组合框中:
Sub InsertSortTest2()
Dim Num As Integer
Dim C As Integer
Dim D As Integer
Dim Temp As Integer
Dim p As Integer
p = Cells.CurrentRegion.Rows.Count
Cells(2, 5) = p 'Just to check'
ReDim Arr(p) As Integer
Dim i As Long
Dim R As Long
For R = 1 To p
i = Cells(R, 1)
Num = p
For C = 0 To Num - 1
Arr(C) = i
Next C
For C = 1 To Num - 1
D = C
While D > 0 And (Arr(D) < Arr(D - 1))
Temp = Arr(D)
Arr(D) = Arr(D - 1)
Arr(D - 1) = Temp
D = D - 1
Wend
Next C
For C = 0 To Num - 1
Range("A" & C + 1).Value = Arr(C)
Next C
Next R
End Sub
将在组合框的顶部插入一个新项目。