How We create a textfield behave as autocomplete by onkeypress evnet in java as Database is Mysql.
Asked
Active
Viewed 495 times
-3
-
2-1 for absolutely no effort shown! – Rahul Mar 25 '13 at 03:54
-
Look up SwingLabs, they have a auto complete decorate for text fields and comboboxes – MadProgrammer Mar 25 '13 at 04:00
1 Answers
1
You should use a DocumentFilter
(thanks MadProgrammer) instead of a KeyListener
. The former is more reliable and easier to deal with.
Also instead of a JTextField
you should use a JComboBox
instead to show a drop down after the user begins typing.
Now I will not put the effort into creating some code for you since you did not show effort in asking the question.
Read up on:

jessechk
- 450
- 5
- 15
-
1I would not. I would suggest a `DocumentFilter` instead over a `DocumentListener`. If you try and modify a text field from within a `DocumentListener` you are likely to cause a exception of some sort (sorry can't remember the type). `DocumentFilter` will allow you to intercept the change before it's applied to the document and modify what is been added/removed – MadProgrammer Mar 25 '13 at 03:59
-