title: How can I add text to combobox from textfield?
body: <p>I want to create a <code>combobox</code> and a <code>textbox</code>.  And user will enter a text into the textbox, and the text will be added as an item of <code>combobox</code>. </p>
  
  <p>How can I do it? I wrote a code, but I couldn't find what will I write in <code>actionlistener</code>.</p>
  
  <pre><code>import java.awt.FlowLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JComboBox;
  import javax.swing.JFrame;
  import javax.swing.JTextField;
  
  public class Q2 extends JFrame {
  
      JTextField t;
      JComboBox combobox = new JComboBox();
  
      public Q2() {
          t = new JTextField("Enter text here", 20);
          t.setEditable(true);
          t.addActionListener(new act());
          add(t);
          add(combobox);
  
          combobox.addItem(t.getText().toString());
          setLayout(new FlowLayout());
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(300, 300);
          setLocationRelativeTo(null);
          setVisible(true);
      }
  
      public class act implements ActionListener {
          public void actionPerformed(ActionEvent e) {
  
          }
      }
  
      public static void main(String[] args) {
          Q2 test = new Q2();
      }
  }
  </code></pre>