ComboBox in Java

ComboBox in Java
  • Version
  • Download 54
  • File Size 1.72 KB
  • Create Date May 12, 2016

ComboBox in Java

A gui program in java that demonstrate how to add a combo box in a window. The program uses swing library. JComboBox is one of the component of swing library.

Source code:

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class ComboBoxInJava extends JFrame {
	
	private JComboBox jcombo;
	private JPanel myjpanel;
	private String[] comboboxitem;
	
	public ComboBoxInJava(){
		
		myjpanel =new JPanel();
		
		comboboxitem = new String[]{"Java", "Visual Basic", "VB.net", "C#", "PHP"};

        jcombo = new JComboBox<>(comboboxitem);
        
       	add(jcombo);
  		
		}	
	
	public static void main (String args[]){
		ComboBoxInJava gui = new ComboBoxInJava();
		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		gui.setTitle("Java GUI");
		gui.setSize(150,90);
		gui.setVisible(true);
		
	}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.