I'm looking for a way to add autocomplete to a JavaFX ComboBox
.
After searching a lot it's time to ask here.
This AutoFillBox
is known but not what I'm searching.
What I want is a editable combobox and while typing the list should filtered. But I want also to open the list without typing and seeing the whole items.
Any idea?
I look around and try something. This look good:
A Keyhandle for select the item with matching start charakter.
I hope this help you
Don't know if this is still relevant, but came to this topic. Tried the upper approaches, made one variation my self. But by far, this fxapps blog one turned out to be best looking(but had to make some modifications since my item list wasn't static, but still...). Hope this will held the next person who will find this topic interesting.
here is a simple one
and a way to use it:
For the sake of simplicity I used String::contains in this code, for better performance use org.apache.commons.lang3.StringUtils::containsIgnoreCase
I found a solution that's working for me:
You can call it with
It's based on this and I customized it to fit my needs.
Feel free to use it and if anybody can improve it, tell me.
Based on Jonatan's answer, I was able to build the following solution:
UPDATE:
In Java 9+, you can access the
ListView
like this:A bit late for the party, but I came across this thread when I had exactly this problem and really liked the answers and the approach, so thanks to everyone who contributed.
But, I don't know what you guys are putting in your
ComboBox
, whenever I left the box without making a specific selection aClassCastException
was thrown. So I am guessing you all mainly use theComboBox
for picking Strings, so I had to come up with a StringConverter since I am using theComboBox
for Objects (FilterCriteria).So here is the converter, hopefully helpful to someone.