Drop Down ComboBox
<p>My ComboBox having many string objects let's say for an instance (&quot;David&quot;, &quot;John&quot;, &quot;Mary&quot;, &quot;Gabriel&quot;, &quot;Anderson&quot;, &quot;Henry&quot;,&quot;Johnson&quot;, &quot;Halstead&quot;, &quot;Annie&quot;, &quot;Jubilee&quot;).
ComboBox is editable.
so, whatever I write in comboBox, in dropdown option I should get only string objects that get matched with the string typed in comboBox.
Let's say,If I have typed &quot;An&quot; in Combobox field then I should have only Annie and Anderson in ComboBox list.A</p>
<pre><code>public void setEditor(ComboBoxEditor editor){
    super.setEditor(editor);
    setEditable(true);
     if (editor.getEditorComponent() instanceof JTextField) {
         inputField = (JTextField) editor.getEditorComponent();
         inputField.addKeyListener(new KeyAdapter() {
         public void keyTyped(KeyEvent e){
             char key = e.getKeyChar();
             String[] matchedString;
             if(Character.isLetterOrDigit(key)||Character.isSpaceChar(key)||key=='\b'){
                 if(key=='\b'){
                    matchedString = getMatchedItems(inputField.getText());
                    removeAllItems();
                    for(int i=0; i&lt;matchedString.length; i++){
                        addItem(matchedString[i]);
                    }
                 }
                    
                 
                 else{
                     matchedString = getMatchedItems(inputField.getText()+key);
                     removeAllItems();
                        for(int i=0; i&lt;matchedString.length; i++){
                            addItem(matchedString[i]);
                        }
                 }
             }
            
         }

        private int getMatchedCount(String currentWord) {
            int n = getItemCount(),count=0;
            for(int i=0; i&lt;n; i++){
                if(((String)getItemAt(i)).toLowerCase().startsWith(currentWord.toLowerCase())){
                    count++;
                }
            }
            return count;
        }
        
        private String[] getMatchedItems(String currentWord){
            int n = getItemCount(),k=0;
            String[] matchedString = new String[getMatchedCount(currentWord)];
            for(int i=0;i&lt;n;i++){
                if(((String)getItemAt(i)).toLowerCase().startsWith(currentWord.toLowerCase())){
                    matchedString[k++] = (String)getItemAt(i);
                }
            }
            return matchedString;
        }
    });
     }
}

public static void main(String[] args) {
    JFrame fr=new JFrame();
    fr.setLayout(null);
    /*List &lt;String&gt; list = new ArrayList&lt;String&gt;();
    list.add(&quot;Shahroz&quot;);
    list.add(&quot;Wasif&quot;);
    list.add(&quot;Akram&quot;);
    */
    String str[] = {&quot;Shahroz&quot;,&quot;saleem&quot;,&quot;Khan&quot;,&quot;Wasif&quot;,&quot;Dutta&quot;,&quot;Piyush&quot;,&quot;Rajat&quot;,&quot;Rehan&quot;,&quot;Rajesh&quot;}; 
    fr.add(new AutoCombo(str));
    fr.setSize(400, 800);
    fr.setVisible(true);
}
</code></pre>
<p>}</p>