title: How to get JComboBox Auto-suggestion
body: <p>Friends, in this project I need a list suggestion as the user types. I have looked at many examples and have started work on it and it somewhat works. The problem is, it only shows the suggestions for the first letter typed and when the second letter is entered, the suggestions disappear.
  Please help me figure out why.
  My code is written so as to auto-complete with the first option in the list when the right arrow key is pressed.</p>
  
  <pre><code>Vector&lt;String&gt; v = new Stack&lt;String&gt;();
  public JTextField tx;
  private boolean hide_flag = false;
  tx = (JTextField)name.getEditor().getEditorComponent();
  tx.addKeyListener(new KeyAdapter() {
          @Override
  public void keyTyped(KeyEvent e){
  EventQueue.invokeLater(new Runnable() {
  
                  @Override
                  public void run() {
                   String text = tx.getText().toUpperCase();
                   if(text.length()==0){
                   name.hidePopup();
                   setModel(new DefaultComboBoxModel(v),"");
                           }
                   else{
                       DefaultComboBoxModel m = getSuggestedModel(v,text);
                        if(m.getSize()==0){
                   name.hidePopup();
                        }
                        else{
                   setModel(m,text);
                    name.showPopup();
                        }
                   }
  
                  }
  
  
              });
   }
          @Override
   public void keyPressed(KeyEvent evt){
   String text = tx.getText();
   int code = evt.getKeyCode();
   if(code == KeyEvent.VK_ENTER){
        if(!v.contains(text)){
                  v.addElement(text);
            }
     hide_flag = true;
   }else if(code == KeyEvent.VK_ESCAPE){
   hide_flag = true ;
   }else if(code == KeyEvent.VK_RIGHT){
     for(int i=0; i&lt; v.size();i++){
         String str = (String)v.elementAt(i);
          if(str.startsWith(text)){
            tx.setText(str);
              return;
          }}
   }
   }
    });
  
    }
   private void setModel(DefaultComboBoxModel Mdl, String str) {
                      name.setModel(Mdl);
                      tx.setText(str);
                  }
   private DefaultComboBoxModel getSuggestedModel(List&lt;String&gt; list , String text){
       DefaultComboBoxModel m = new  DefaultComboBoxModel(); 
       for(String s : list){
           if(s.startsWith(text)){
         m.addElement(s);  
       }
       }
       return m;
   }
  </code></pre>
  
  <p>I want the auto-complete to be able to suggest words as I type. More than just the first letter.</p>