- Version
- Download 54
- File Size 1.72 KB
- Create Date May 12, 2016
- Download
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);
}
}