In this tutorials, I am going to show you how to use Java JComboBox. Java ComboBox is a swing component that combines drop down with editable field.

Java JComboBox :
package com.onlinetutorialspoint.swing;

import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.activation.MailcapCommandMap;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class JComboBoxDemo extends JFrame {

    private JComboBox comboBox;
    private JLabel label;
    private static final String[] names = {

    private Icon[] icons = {
            new ImageIcon("C:\\images\\bulb1.gif"),
            new ImageIcon("C:\\images\\bulb2.gif"),
            new ImageIcon("C:\\images\\bulb3.gif") };

    JComboBoxDemo() {
        super("JCombobox Demo");

        setLayout(new FlowLayout());
        comboBox = new JComboBox(names);

        comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
        label = new JLabel(icons[0]);

    public static void main(String[] args) {
        JComboBoxDemo jComboBoxDemo = new JComboBoxDemo();
        jComboBoxDemo.setSize(350, 150);


Output :

Java JComboBox

Changing the Items :

Java JComboBox 1

Editable JComboBox :

We can make the JComboBox as editable by using setEditable(true) like below.

Enable Editing

Output :

Java JComboBox Editable

Happy Learning 🙂