Shahad
Shahad

Reputation: 3

Adding to JComboBox without using an array

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.

Upvotes: 0

Views: 70

Answers (2)

Tim B
Tim B

Reputation: 41208

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

Upvotes: 1

Andrew Thompson
Andrew Thompson

Reputation: 168845

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

Upvotes: 2

Related Questions