1

I need to create a JTextField (or any component where I can type something) and it has to offer a list of dynamicaly populated values. When I type a new character, the propositions are updated (Like Ajax does)

One particularity is that the user can only choose a value that was populated. I need that for my users to select an existing city from a database.

What would be the easiest way to make it with Swing ?

Thank you.

Vincent Roye
  • 2,751
  • 7
  • 33
  • 53

3 Answers3

4

You can implements Auto complete ComboBox / JFextField based on standard Java API, there aren't any issues with Focus or Caret nor with performance for largiest Arrays for autocompleted JComboBox and JTextField

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
3

I have used the JIDE Common Layer for autocompletion in Java Swing. Take a look at the WebStart demo.

It's free and open source, and if the provided autocompletion options don't quite match what you are trying to do I found it really easy to plug in my own logic.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Richard Neish
  • 8,414
  • 4
  • 39
  • 69
1

You can use Swingx.Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications. Highlights include:

Sorting, filtering, highlighting for tables, trees, and lists Find/search Auto-completion Login/authentication framework TreeTable component Collapsible panel component Date picker component Tip-of-the-Day component

Vijay Vankhede
  • 3,018
  • 1
  • 26
  • 46