Java – Combo Box and Search Component in Java


My goal is to create some kind of swing component that can do two things:

  1. Function as a combo box (select from a list of values)
  2. Allow a user to type into the component and only display the relevant items from the original list (like some AJAX search boxes online)

I would really like to do this by customizing an existing swing component so I don't have to write it from scratch, but so far I have not found anything that can do this. I have considered the massive amounts of hacks that it would take to possibly get a JComboBox to do this, but I don't really think that will work.

Any recommendations on what the best way to do this would be? Bonus points for solutions that aren't 100% custom code.

Best Solution

What you are looking for can be found be using autocomplete in your search strings.

Comboboxes which support what you want for sure exist in several libraries just one example:

Glazed Lists

The following site contains a few samples (for glazedlists too) and further links to other libraries. It's a bit dated but I guess the information is still ok.

Adding Auto-Completion Support to Swing Comboboxes