开发者

How to make an auto-complete list when I start to type in the textfield?

I 开发者_开发技巧have a textfield and if I want to write something to the field, it will show me the list of possible options regarding to that letter and I think this is called an auto complete.

Could someone give me an idea or a sample on how to do it?

Thanks..


Take a combo box and listen to all changes in the textfield. On every event, read the actual content and query your source list for possible matches. Then use the result to populate the associated list.

You may want to start autocompletion once the user has entered two or three letters, otherwise the list may get too long..


look here is AutoCompleteComboBox / JFextField, and there are two classes one for JComboBox, second for JTextField, notice auto-complete functionality requires both classes for that


I feeling generous as you really should google ...

As the user types, you'd need to query your DB with a like '<userInput>%' and return the results into a pulldown. You probably want to wait for a pause in the user's typing so as not to hammer your DB.

In the absence of a database, a data structure that would work well for this is called a Trie as you can traverse it past the initial input and present all the subsequent words.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜