javaswingswingxjxtableapproximate-nn-searching

How to disable JXTable default search action?


I have a JXTable in my swing app. When I press ctrl+F on the table, default search panel is opening.

enter image description here

This panel finds only substrings. I need to find similar words with my InputText. For example, I write "test" result may be "tost", "tests", "est", "tst" and etc. How do i change this searching method to my own algorithm ? Is it possible ? Or Should I disable default seaching and create my own ?


Solution

  • Override the JXTable#getSearchable method and return your own custom Searchable implementation.

    Note that the default implementation always returns the same instance (lazily created):

    public Searchable getSearchable() {
        if (searchable == null) {
            searchable = new TableSearchable(this);
        }
        return searchable;
    }
    

    You might want to keep this in mind when overriding the method. I have no idea what the effect would be to always return a new instance.