chintan
chintan

Reputation: 51

Invoke search in database on each keystroke of JTextField

I want to add a search facility to JTextField, so that when a user enters text to the JTextField, it retrieves related values from the database. This way, if the user selects that value, it helps avoids duplication of values.

In addition, when I should enter ABCD, it retrieves related keys from the database as (ABCD EFG,ABCD SDLFH, etc....) and the user should select an appropriate one from that.

Upvotes: 0

Views: 164

Answers (2)

adev
adev

Reputation: 377

use this code written by Scott Example: Adding Autocomplete to JTextField

Upvotes: 0

Krease
Krease

Reputation: 16215

It sounds like you want to add some form of autocomplete functionality to your JTextField object. The question JTextField AutoComplete discusses this as well. The list of valid values is not dynamically retrieved from a database, though you can look at the code samples linked from there and probably change them to do queries when appropriate.

I'd start with getting familiar with how AutoCompleteDecorator from the SwingX library works (one of the answers from the above question), since the source is available here.

Upvotes: 1

Related Questions