Java JComboBox Editable Example

By | 2017-11-26T16:38:06+00:00 November 26th, 2017|java|0 Comments

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.


Output :

Java JComboBox Editable

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment