Manu

Saturday, November 19, 2016

write a program which use JComboBox in Swing.


package javaapplication1;
import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MyCombobox extends JFrame
{
    String lang[] = {"gujrati","hindi","Franch","English","Marathi"};
    private MyCombobox(String title) {
        super(title);
        setLayout(new FlowLayout());

        JLabel jl1 = new JLabel("Select Your choice");
        JComboBox combo = new JComboBox();

        for(int i = 0;i<lang.length;i++)
        {
          combo.addItem(lang[i]);
        }

         add(jl1);
         add(combo);
    }

      public static void main(String args[])
      {
          MyCombobox mcb = new MyCombobox("Combobox here");
          mcb.setSize(300,400);
          mcb.setVisible(true);
      }
}

Output :


No comments:

Post a Comment