0

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.

Krease
  • 15,805
  • 8
  • 54
  • 86
chintan
  • 51
  • 1
  • 1
  • 4

2 Answers2

1

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.

Community
  • 1
  • 1
Krease
  • 15,805
  • 8
  • 54
  • 86
0

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

adev
  • 367
  • 1
  • 3
  • 20