user7941771
user7941771

Reputation: 13

How to add JComboBox(Object[] items) to jComboBox1.addItem(String items);

Object[] items = {new ComboItem("A"), new ComboItem("B"),
            new ComboItem("1", false), new ComboItem("2", false),
            new ComboItem("abc"), new ComboItem("def")};

as Above, I have created a Object Array of items to be put inside a jComboBox1 component (Which I have been dragged and dropped into my JFrame) But I cannot normally add this items (e.i Object[] items) into my jComboBox1

But I can do it like this: (But this is not what I want)

JComboBox combo = new JComboBox(items);

I don't want to do this by creating a new JComboBox object I want to add it into my Dragged and Dropped jComboBox1

can you anyone give any suggestion?

Upvotes: 0

Views: 985

Answers (2)

Sergiy Medvynskyy
Sergiy Medvynskyy

Reputation: 11327

Try following:

jComboBox1.setModel(new DefaultComboBoxModel(items));

Upvotes: 1

PrabaharanKathiresan
PrabaharanKathiresan

Reputation: 1129

Initiate the JComboBox with array of Items. Whenever you want modify items in combobox add/remove the item from the array and do a repaint after the change.

Upvotes: 0

Related Questions