How to list suggestions to when typing inside the text field

nath picture nath · Jul 13, 2011 · Viewed 15.7k times · Source

Hi in my Java swing application I need to show all possible existing entries with same initial characters while user typing in a text field. Lets say user type letter 'A' in a text field which should be a country 'America' and 'Africa' would be suggestions. So that user can select one from the list. Country list resides in my database. I know how to retrieve data from DB. But I don't know how to list them and which components I should use to achieve. Can any one guide me? Or if you can provide an example, that would be great.

Answer

Konrad Garus picture Konrad Garus · Jul 13, 2011

You could use the autocomplete package from SwingX. Google for "swingx autocomplete" if you need more real life examples, but the simplest way is creating a JComboBox and calling AutoCompleteDecorator.decorate(comboBox); on it.