问题
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