Best strategy for autocomplete component

What would your way to make an autocomplete component?
Is there any available example somewhere made with JUCE?

We don’t have anything in JUCE, but I’ve done it by finding the highest consecutive character matches and displaying them in that order.

1 Like

My idea was to use a TextEditor linked to a ListBox.
I read a thread about using a ComboBox.
Or perhaps make my own component from scratch.

Is your sorting heuristic available publicly?

FYI: Edit distance - Wikipedia

// members
Label textInput;
Label textAutoComplete;
TextEditor* editor;
std::vector myList;


textAutoComplete.onEditorShow =this

textInput & textAutoComplete = same bounds;

String match = editor.getText();

for(auto& item:myList)
else textAutoComplete.setText(“”);

1 Like

By matching with the start of the string only, "table" will not be suggested for "able".

I tried to use a Levenshtein distance but the result is bad.


1 Like

Thanks ; interesting… but seems overkill for my use case.

Anyway i ended by using a homemade stupid distance computation.
Filter items that doesn’t contain the string as substring.
Sum prefix and suffix lengths (weighted to prefer matches near the start).
It seems to give good suggestions.

OT but related, that is exactly what I hate about the juce docs, that I cannot type dragging and get isDragging and getDragging… that would make life so much simpler…

So +1 for matching sub strings


If you’re on macOS and want to get even slightly further off-topic, and I’m not in anyway affiliated to, but am a recent convert to Dash (Dash for macOS - API Documentation Browser, Snippet Manager - Kapeli)


Dash is awesome, you just have to really remember to re-import/generate the docsets with every JUCE/Tracktion udpate … :wink: Been bitten by relying on a stale Dash docset a few too many times.

1 Like