Autocomplete anywhere for the word JComboBox / JTextField

I found various solutions for adding autocomplete on JComboBox, but they all work with autocomplete from the very beginning. I am looking for a solution similar to JQueryUI AutoComplete (if you enter av in a text field, it pops up in Java and JavaScript).

For example, if I have the following elements:

  • "Red"
  • "Blue"
  • "Green"

If I enter n, I would like to have a match with Green, since it contains n.

Here is a solution I tested previously that only matches from the start:

  • AutoCompleteDecorator.decorate (comboBox) from SwingX
  • AutoCompleteSupport.install (COMBOBOX, GlazedLists.eventListOf (elements)); from GlazedLists
  • jautocomp from jautocomp
  • Java2sAutoComboBox.java

All of the above solutions correspond to the beginning (everyone uses the startWith method), which I am not looking for.

Do you know other solutions like jQueryUI implementation?

+4
source share
1 answer

You can use these methods by sending substrings to them instead of the full string:

1. check against the full string 2. check against the substring starting at position 1 ... n. check against the substring starting at position `n-1` 

limited to full line length

So, for your example, you would do the following:

  • Does β€œgreen” correspond to β€œn” at the beginning? No β†’ next position
  • Does "reen" match "n" at the beginning? No β†’ next position
  • First, "nen" matches "n"? No β†’ next position
  • Does "ru" first match "n"? No β†’ next position
  • Does "n" match "n" at the beginning? Yes β†’ select the full word ("Green") as the match
0
source

Source: https://habr.com/ru/post/1413972/


All Articles