JList, JTable and JTree are three data-rich components. They can be used
to display a huge amount of data so searching function will be very a useful feature in those components.
Searchable is such a class that can make JList, JTable and JTree searchable.
User can simply type in any string they want to search for and use arrow keys to navigate
to next or previous occurrence.
Searchable is a base abstract class. ListSearchable, TableSearchable and TreeSearchable
are implementations to make JList, JTable and JTree searchable respectively. For each implementation, there are
five methods need to be implemented.
Please look at the javadoc of each method to learn more details.
The keys used by this class are fully customizable. Subclass can override the methods such as isActivateKey(KeyEvent) ,
isDeactivateKey(KeyEvent) , isFindFirstKey(KeyEvent) , isFindLastKey(KeyEvent) ,
isFindNextKey(KeyEvent) , isFindPreviousKey(KeyEvent) to provide its own set of keys.
In addition to press up/down arrow to find next occurrence or previous occurrence of
particular string, there are several other features that are very handy.
Multiple selection feature - If you press CTRL key and hold it while pressing up and down arrow,
it will find next/previous occurence while keeping existing selections.
Select all feature - If you type in a searching text and press CTRL+A, all the occurrences of
that searching string will be selected. This is a very handy feature.
For example you want to delete all rows in a table whose name column begins with "old".
So you can type in "old" and press CTRL+A, now all rows begining with "old" will
be selected. Pressing delete will delete all of them.
Basic regular expression support - It allows '?' to match any letter or digit,
or '*' to match several letters or digits.
Even though it's possible to implement full regular expression support, we don't want to do that.
The reason is the regular expression is very complex, it's probably not a good idea to let user
type in such a complex expression in a small popup window. However if your user is very familiar
with regular expression, you can add the feature to Searchable. All you need to do
is to override compare(String, String) method
and implement by yourself.
As this is an abstract class, please refer to to javadoc of ListSearchable , TreeSearchable , and TableSearchable to find out
how to use it with JList, JTree and JTable respectively.
This component has a timer. If user types very fast, it will accumulate them together and generate only one searching action.
The timer can be controlled by setSearchingDelay(int) .
By default we will use lightweight popup for the sake of performance. But if you use heavyweight component
which could obscure the lightweight popup, you can call setHeavyweightComponentEnabled(boolean) to true
so that heavyweight popup will be used.
Searchableis such a class that can make JList, JTable and JTree searchable. User can simply type in any string they want to search for and use arrow keys to navigate to next or previous occurrence.Searchableis a base abstract class.ListSearchable,TableSearchableandTreeSearchableare implementations to make JList, JTable and JTree searchable respectively. For each implementation, there are five methods need to be implemented.
Please look at the javadoc of each method to learn more details. The keys used by this class are fully customizable. Subclass can override the methods such as isActivateKey(KeyEvent) , isDeactivateKey(KeyEvent) , isFindFirstKey(KeyEvent) , isFindLastKey(KeyEvent) , isFindNextKey(KeyEvent) , isFindPreviousKey(KeyEvent) to provide its own set of keys. In addition to press up/down arrow to find next occurrence or previous occurrence of particular string, there are several other features that are very handy. Multiple selection feature - If you press CTRL key and hold it while pressing up and down arrow, it will find next/previous occurence while keeping existing selections.protected abstract int getSelectedIndex()protected abstract void setSelectedIndex(int index, boolean incremental)protected abstract int getElementCount()protected abstract Object getElementAt(int index)protected abstract String convertElementToString(Object element)Select all feature - If you type in a searching text and press CTRL+A, all the occurrences of that searching string will be selected. This is a very handy feature. For example you want to delete all rows in a table whose name column begins with "old". So you can type in "old" and press CTRL+A, now all rows begining with "old" will be selected. Pressing delete will delete all of them.
Basic regular expression support - It allows '?' to match any letter or digit, or '*' to match several letters or digits. Even though it's possible to implement full regular expression support, we don't want to do that. The reason is the regular expression is very complex, it's probably not a good idea to let user type in such a complex expression in a small popup window. However if your user is very familiar with regular expression, you can add the feature to
Searchable. All you need to do is to override compare(String, String) method and implement by yourself. As this is an abstract class, please refer to to javadoc of ListSearchable , TreeSearchable , and TableSearchable to find out how to use it with JList, JTree and JTable respectively. This component has a timer. If user types very fast, it will accumulate them together and generate only one searching action. The timer can be controlled by setSearchingDelay(int) . By default we will use lightweight popup for the sake of performance. But if you use heavyweight component which could obscure the lightweight popup, you can call setHeavyweightComponentEnabled(boolean) to true so that heavyweight popup will be used.