Java JComboBox Autocomplete [closed]

风格不统一 提交于 2019-12-10 19:05:04

问题


I have an ArrayList of People - which is made up of a Name, email, and a few numbers (however they are all strings). I use this list to populate a JComboBox on my form.

What I want to implement is an auto-complete JComboBox, so, for example, when typing in Tim:

Press "T" -> It will drop-down display everything beginning with "T"

Press "i" -> It will drop-down display everything that begins with "Ti"

Press "m" -> It will drop down display everything that has "Tim" at the beginning.

I've tried a few ways - looked at things like SwingX, but it seems that servers are down and I can't access any documentation. I have tried creating my own algorithm, but it's getting quite complicated and i've been going down some dead ends. I was wondering if anyone knew of any good methods to achieve what I am trying?

Thank you.


回答1:


I was wondering if anyone knew of any good methods to achieve what I am trying?

Use any of the existing libraries that provide autocompletion. SwingX has indeed such a feature in the API, but others are available as well.

Take a look at this article which contains more information on autocompletion in Java and contains links to some 3th party libs which offer this functionality



来源:https://stackoverflow.com/questions/11583344/java-jcombobox-autocomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!