Search code examples
javaswingautocompletejtextfieldautosuggest

How to list suggestions to when typing inside the text field


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.


Solution

  • 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.