How to implement AutoComplete TextField using ControlsFX

时光总嘲笑我的痴心妄想 提交于 2019-12-23 15:29:10

问题


I'm using the latest version(8.0.5) of ControlsFX and I think I need a little help with the AutoComplete TextField because I'm very new at this.

I got this code from here

AutoCompletionTextFieldBinding.createBinding(
MyTxtField,
SuggestionProvider.create("Hey", "Hello", "Hello World", "Apple", "Cool", "Costa", "Cola", "Coca Cola")
);

But it show a error: method SuggestionProvider is not applicable.

Any advice to implement this autocomplete in order to have an array like a dictionary with ID and VALUE?


回答1:


If you check the transcript to which you have quoted the code https://bitbucket.org/controlsfx/controlsfx/pull-request/196/auto-complete-support-see-127/diff (early feb) and the release date of controlsfx 8.05 dated 4 march http://fxexperience.com/controlsfx/ , likely explanation is that the code is likely not working because what you have quoted is just experimental API that yet to be finalized then. The final version is the one currently working in the final 8.05 as in

TextFields.bindAutoCompletion(
            textField,
            "Hey", "Hello", "Hello World", "Apple", "Cool", "Costa", "Cola", "Coca Cola");

and other API you can check using autocomplete from your IDE

I recommend checking out controlfx 8.05 samples to look at the source code and that will help a lot :}




回答2:


Now, you can use the AutoCompletionTextFieldBinding as the following:

TextField textField = new TextField();
new AutoCompletionTextFieldBinding(textField, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection>() {
    @Override
    public Collection call(AutoCompletionBinding.ISuggestionRequest param) {
        return Arrays.asList("Option 1", "Option 2");
    }
});


来源:https://stackoverflow.com/questions/22749621/how-to-implement-autocomplete-textfield-using-controlsfx

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