Create a combo box and initialize its contents from an array - Java Swing

Java examples for Swing:JComboBox

Description

Create a combo box and initialize its contents from an array

Demo Code

import javax.swing.JComboBox;

public class Main {
  public static void main(String[] args) {
    String[] theSeven = { "A", "B", "C", "D", "E", "F", "G" };

    JComboBox combo1 = new JComboBox(theSeven);
  }/* w w  w  .j  a va  2  s  .c  om*/
}

If you have an existing Vector object with the data you want to display:

JComboBox combo1 = new JComboBox(vector1);
JComboBox combo1 = new JComboBox(arraylist1.toArray());

Related Tutorials