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:



Post a Comment

Copyright © Rough Record. Designed by OddThemes