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.
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.
You should try JComboBox as an autosuggest box instead of JTextField. But if you still want it to be done using JTextField then...
there are two classes (you are needed both for correct funcionalities), Auto Complete JTextField and AutoComplete JComboBox, excelent is that you can set if is strict (allows typing if List doesn't contains ) or not
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With