Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.Arrays;

import javax.swing.JComboBox;
import javax.swing.JFrame;

public class Main extends JFrame {
    public Main() {

        super();
        java.util.List<String> list = new ArrayList<String>();

        list.add("A");
        list.add("B");
        list.add("C");
        list.add("D");

        Object[] arrayObject = list.toArray();
        String[] data = Arrays.copyOf(arrayObject, arrayObject.length, String[].class); // java 1.6+
        JComboBox<String> combo = new JComboBox<>(data);

        setLayout(new FlowLayout(FlowLayout.CENTER));
        add(combo, BorderLayout.CENTER);
    }

    public static void main(String[] args) {
        Main g = new Main();
        g.setVisible(true);
        g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        g.setBounds(100, 100, 300, 300);
    }
}