25 April 2012

create combobox using jframe


import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;


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

import javax.swing.JTextField;


public class CreateCombobox extends JFrame implements ItemListener{
     
      JTextField output1;
      JComboBox combobox1;

     
     
      public CreateTextbox(){
           
            setLayout(null);
           
              String[] str = {"item1","item2","item3","item4"};
                  combobox1 = new JComboBox(str);
                  combobox1.setBounds(100,50,100,20);
                  combobox1.addItemListener(this);
                  add(combobox1);
                     
              output1 = new JTextField(5);
              output1.setBounds(100,200,100,20);
              add(output1);
             
      }
     
      public void itemStateChanged(ItemEvent e) {

            output1.setText(combobox1.getSelectedItem().toString());
           
      }
     
     
      public static void main (String[] args)
    {
            CreateTextbox me = new CreateTextbox();
         me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         me.setVisible(true);
         me.setLocation(550, 500);
         me.setSize(300, 300);
         me. setTitle("Create Textbox");

    }
     
}


output:



1 comments:

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;