Java Program to add items in JComboBox by user input

In this program, you will learn how to add items in JComboBox by user input in java.

JComboBox cb;


Example: How to add items in JComboBox by user input in java.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

class Test implements ActionListener {

    JButton jb1;
    JComboBox cb;

    JTextField t1;
    JFrame f;

    Test() {

        f = new JFrame("ComboBox Example");

        cb = new JComboBox();
        cb.setBounds(50, 30, 150, 30);

        t1 = new JTextField();
        t1.setBounds(60, 100, 120, 30);

        jb1 = new JButton("Add Item");
        jb1.setBounds(50, 200, 100, 30);


        f.setSize(600, 500);

    public void actionPerformed(ActionEvent e) {

    public static void main(String args[]) {
        Test t = new Test();


Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.