public class SearchableUtils
extends java.lang.Object
SearchableUtils.installSearchable(component);
The component could be a JList, JTree or JTable. If you need to further customize some attributes of Searchable, you
can assign a variable that returns from installSearchable().
Searchable searchable = SearchableUtils.installSearchable(component);
// further configure it
searchable.setCaseSensitive(true);
// ...
Usually you don't need to uninstall the searchable from the component. But if for some reason, you need to disable
the searchable feature of the component, you can call uninstallSearchable().
Searchable searchable = SearchableUtils.installSearchable(component);
// ...
// Now disable it
SearchableUtils.uninstallSearchable(searchable);
There is a small trick that you should know. JTree and JList implemented partially the quick search feature so that
when you type in the first character, it will jump to the first occurrence. This feature sometimes conflicts with the
Searchable we provided. So it'd better if you disable the JTree or JList default feature by creating JTree and JList
with getNextMatch method overridden. See below
JTree tree = new JTree(...) {
public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias) {
return null;
}
};
JList list = new JList(...){
public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
return -1;
}
};
Constructor | Description |
---|---|
SearchableUtils() |
Modifier and Type | Method | Description |
---|---|---|
static ComboBoxSearchable |
installSearchable(javax.swing.JComboBox combobox) |
Installs the searchable function onto a JComboBox.
|
static ListSearchable |
installSearchable(javax.swing.JList list) |
Installs the searchable function onto a JList.
|
static TableSearchable |
installSearchable(javax.swing.JTable table) |
Installs the searchable function onto a JTable.
|
static TreeSearchable |
installSearchable(javax.swing.JTree tree) |
Installs the searchable function onto a JTree.
|
static TextComponentSearchable |
installSearchable(javax.swing.text.JTextComponent textComponent) |
Installs the searchable function onto a JTextComponent.
|
static void |
uninstallSearchable(Searchable searchable) |
Uninstall the searchable that was installed to a component
|
static void |
uninstallSearchable(javax.swing.JComponent component) |
Uninstall the searchable that was installed to a component
|
public static TreeSearchable installSearchable(javax.swing.JTree tree)
tree
- the JTree to install searchablepublic static TableSearchable installSearchable(javax.swing.JTable table)
table
- the JTable to install searchablepublic static ListSearchable installSearchable(javax.swing.JList list)
list
- the JList to install searchablepublic static ComboBoxSearchable installSearchable(javax.swing.JComboBox combobox)
combobox
- the combo box to install searchablepublic static TextComponentSearchable installSearchable(javax.swing.text.JTextComponent textComponent)
textComponent
- the text component to install searchablepublic static void uninstallSearchable(Searchable searchable)
searchable
- the searchable.public static void uninstallSearchable(javax.swing.JComponent component)
component
- the component that has a searchable installed.