Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

Java Swing JComboBox

The JComboBoxis an in-built class(component) which is used to create the combobox (drop-down list) in Swing. Generally Combo box is a combination of text fields and drop-down list.Following is the constructor for JComboBox. JComboBox(String str[])

JComboBox Example
importjavax.swing.*;
importjava.awt.event.*;
importjava.awt.*;
public class JComboBoxDemo extends JFrame
{
	String name[] = {"Akshay","Santosh","Tilan","Silan"};  //list of name. 
	publicJComboBoxDemo() 
	{
		JComboBoxjc = new JComboBox(name);	//initialzing combo box with list of name. 
		add(jc);				//adding JComboBox to frame. 
		setLayout(new FlowLayout());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(300, 300);
		setVisible(true);
	}
	public static void main(String[] args)
	{
		newJComboBoxDemo();
	}
}
Output:

pic

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext