0
    ArrayList<String> aniNames = new ArrayList<>();

I made connection with Database and stored 7K anime names in above ArrayList.

    JFXAutoCompletePopup<String> autoCompPop = new JFXAutoCompletePopup<>();
    for (int i=0; i<aniNames.size(); i++){
        autoCompPop.getSuggestions().addAll(aniNames.get(i));
    }
    autoCompPop.setSelectionHandler(event ->{
        autoTF.setText(event.getObject());
    });

    autoTF.textProperty().addListener(observable -> {
    autoCompPop.filter(string -> string.toLowerCase().contains(autoTF.getText().toLowerCase()));
    if (autoCompPop.getFilteredSuggestions().isEmpty() || autoTF.getText().isEmpty()) {
        autoCompPop.hide();
    } else {
        autoCompPop.show(autoTF);
    }
});

So I wrote this program in which when I type something, it shows auto completion popup.

When I type a single letter, lets say "a" or any other, It shows almost all anime having "a" in there names, which means almost all 7k anime.

I want to limit the number of results it shows if exceeds a certain number, for example, if more than 20 anime have "a" in their name then I want it to show only first 20 anime in the popup.

sygmus1897
  • 41
  • 4

1 Answers1

0

Changing:

autoCompPop.filter(string -> string.toLowerCase().contains(autoTF.getText().toLowerCase()));

to:

autoCompPop.filter(string -> string.toLowerCase().startsWith(autoTF.getText().toLowerCase()));

might help you out, not by forceably limiting results, but by telling the popup to search for names that start with the entered text instead of names that contain the entered text, thus cutting down on the number of results.

It doesn't seem that JFXAutocompletePopup has a method for limiting search results, as setCellLimit() only limits the number of visible cells (essentially shortening the height of the popup and not the actual number of items). JFXAutocompletePopup source code