TreeSearchable
is an concrete implementation of {@link Searchable} that enables the search function inJTree. It's very simple to use it. Assuming you have a JTree, all you need to do is to call
Now the JTree will have the search function. JTree tree = ....; TreeSearchable searchable = new TreeSearchable(tree);
JTree tree = ....; TreeSearchable searchable = new TreeSearchable(tree) { protected String convertElementToString(Object object) { ... } };
Additional customization can be done on the base Searchable class such as background and foreground color, keystrokes, case sensitivity. JTree actually has a simple searchable feature but has flaws. It will affect our searchable feature. To workaround it, you can override getNextMatch method and always return -1 when you create your JList. JTree tree = new JTree(...) { public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) { return null; } };
|
|