JComboBox

The JComboBox control is a new control in Swing. It is a combination of a textfield and a drop-down list. The JComboBox class extends JComponent. A combo-box initially displays one entry. However, it can and a drop-down list that allows a user to select a different entry. We can also type our selection into the text field.

Program

vcxxxc

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JComboBox;
import java.awt.FlowLayout;

class Frame extends JFrame {
   
    Frame()
    {
        setTitle("JComboBox");
        setLayout(new FlowLayout());
        setJComboBox();
        setSize(700, 200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
   
    private void setJComboBox()
    {
        String[] item = {"C","C++","Java","Php"};
        JComboBox jb = new JComboBox(item);
        add(jb);
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
       Frame frame = new Frame();
    }
}

Leave a Comment