Autocomplete in a TextField
I would like to add autocomplete functionality to some Textfields. It should work like the one in windows search textfield. I mean that particularly a popup with the matches should appear under the textfield.
My first attemts to do so using org.jdesktop.swingx.autocomplete failed.
Here is my approach:
JTextField textfield = new JTextField();
DefaultListModel model = new DefaultListModel();
ListAdaptor adaptor = new ListAdaptor(new JList(model), textfield);
AutoCompleteDocument autoDoc = new AutoCompleteDocument(adaptor, false);
AutoCompleteDecorator.decorate(textfield, autoDoc, adaptor);
The first thing is that the provided JList wasn't used for the popup as my naive expectation was. So there was no list with matches displayed.
Is it possible to implement the desired functionality using the org.jdesktop.swingx.autocomplete package?
If yes, what would be the best way to do it? Implement my own AbstractAutoCompleteAdaptor?
The second thing is that I was not able to provide a value which is the beginning of an already existing value (in my example it would be "aa" what is the beginning of "aaa"). On loosing focus the value gets automatically autocompleted :-)
I assume its a bug.
P.S. BTW SwingLabs is a great lib!