在不使用数组的情况下添加到JComboBox

时间:2023-01-27 23:44:17

Is it possible to add a String to a JComboBox without using an array? I have an adding button that should add to combo box after clicking on it but I don't know how to do that.

是否可以在不使用数组的情况下将字符串添加到JComboBox?我有一个添加按钮,应该在点击它后添加到组合框但我不知道该怎么做。

2 个解决方案

#1


2  

Use DefaultComboBoxModel.addElement(E). More generally, see How to Use Combo Boxes.

使用DefaultComboBoxModel.addElement(E)。更一般地说,请参阅如何使用组合框。

#2


1  

Andrew is correct, you don't need to go to the model though. The jComboBox class provides an addItem method for you.

安德鲁是对的,你不需要去模特。 jComboBox类为您提供addItem方法。

#1


2  

Use DefaultComboBoxModel.addElement(E). More generally, see How to Use Combo Boxes.

使用DefaultComboBoxModel.addElement(E)。更一般地说,请参阅如何使用组合框。

#2


1  

Andrew is correct, you don't need to go to the model though. The jComboBox class provides an addItem method for you.

安德鲁是对的,你不需要去模特。 jComboBox类为您提供addItem方法。