title: jcombobox filter in java - Look and feel independent
body: <p>I have a simple JComboBox filter code like this :</p>
  
  <pre><code>import java.awt.event.KeyAdapter;
  import java.awt.event.KeyEvent;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.swing.DefaultComboBoxModel;
  import javax.swing.JComboBox;
  import javax.swing.JFrame;
  import javax.swing.JTextField;
  import javax.swing.SwingUtilities;
  import javax.swing.UIManager;
  
  public class FilterComboBox extends JComboBox {
      private List&lt;String&gt; array;
  
      public FilterComboBox(List&lt;String&gt; array) {
          super(array.toArray());
          this.array = array;
          this.setEditable(true);
          final JTextField textfield = (JTextField) this.getEditor().getEditorComponent();
          textfield.addKeyListener(new KeyAdapter() {
              public void keyReleased(KeyEvent ke) {
                  SwingUtilities.invokeLater(new Runnable() {
                      public void run() {
                          comboFilter(textfield.getText());
                      }
                  });
              }
          });
  
      }
  
      public void comboFilter(String enteredText) {
          List&lt;String&gt; filterArray= new ArrayList&lt;String&gt;();
          for (int i = 0; i &lt; array.size(); i++) {
              if (array.get(i).toLowerCase().contains(enteredText.toLowerCase())) {
                  filterArray.add(array.get(i));
              }
          }
          if (filterArray.size() &gt; 0) {
              this.setModel(new DefaultComboBoxModel(filterArray.toArray()));
              this.setSelectedItem(enteredText);
              this.showPopup();
          }
          else {
              this.hidePopup();
          }
      }
  
      /* Testing Codes */
      public static List&lt;String&gt; populateArray() {
          List&lt;String&gt; test = new ArrayList&lt;String&gt;();
          test.add("");
          test.add("Mountain Flight");
          test.add("Mount Climbing");
          test.add("Trekking");
          test.add("Rafting");
          test.add("Jungle Safari");
          test.add("Bungie Jumping");
          test.add("Para Gliding");
          return test;
      }
  
      public static void makeUI() {
          JFrame frame = new JFrame("Adventure in Nepal - Combo Filter Test");
          FilterComboBox acb = new FilterComboBox(populateArray());
          frame.getContentPane().add(acb);
          frame.pack();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
      }
  
      public static void main(String[] args) throws Exception {
  
          //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
          makeUI();
      }
  }
  </code></pre>
  
  <p>The performance of the combo filter is not so good but it is fine for few data set. My problem is - when I remove the comment <code>UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");</code> to change look and feel, the filter doesn't work. In WindowsLookAndFeel, the combo box only takes single character in it by replacing the previously entered character.</p>
  
  <p><img src="https://i.stack.imgur.com/KY9uP.png" alt="Different Outputs after typing &#39;moun&#39;"></p>
  
  <p>Can you please tell me whats going on? <a href="https://stackoverflow.com/a/10455018/607637">Manoj Shrestha's answer below</a> helps in some way but , can you please provide some other suggestions to achieve combo box filter in Java?</p>