Java Swing Tutorial - Java JComboBox(E [] items) Constructor








Syntax

JComboBox(E [] items) constructor from JComboBox has the following syntax.

public JComboBox(E [] items)

Example

In the following code shows how to use JComboBox.JComboBox(E [] items) constructor.

/*  www.j  a  v  a 2  s .  c  o  m*/
  
import javax.swing.JComboBox;
import javax.swing.JFrame;

public class Main extends JFrame {
  public Main() {
    super();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox jcb = new JComboBox(new String[]{"a","b","c","d"});

    getContentPane().add(jcb);

    setSize(200, 50);
    setVisible(true);
  }

  public static void main(String[] args) {
    new Main();
  }
}