| java.lang.Object com.jidesoft.swing.Searchable com.jidesoft.swing.TableSearchable
TableSearchable | public class TableSearchable extends Searchable implements TableModelListener,PropertyChangeListener(Code) | | TableSearchable is an concrete implementation of
Searchable that enables the search function in JTable.
It's very simple to use it. Assuming you have a JTable, all you need to do is to
call
JTable table = ....;
TableSearchable searchable = new TableSearchable(table);
Now the JTable will have the search function.
As JTable is a two dimension data, the search is a little different from JList and JTree which both have
one dimension data. So there is a little work you need to do in order to convert from two dimension data
to one dimension data. We use the selection mode to determine how to convert. There is a special property
called mainIndex. You can set it using setMainIndex(). If the JTable is in row selection mode, mainIndex will
be the column that you want search at. Please note you can change mainIndex at any time.
On the other hand, if the JTable is in column selection mode, mainIndex will be the row that you want search at.
There is one more case when cell selection is enabled. In this case, mainIndex will be ignore; all cells will be searched.
In three cases above, the keys for find next and find previous are different too. In row selection mode, up/down arrow are the keys.
In column selection mode, left/right arrow are keys. In cell selection mode, both up and left arrow are keys to
find previous occurence, both down and right arrow are keys to find next occurence.
In addition, you might need to override convertElementToString() to provide you own algorithm to do the conversion.
JTable table = ....;
TableSearchable searchable = new TableSearchable(table) {
protected String convertElementToString(Object object) {
...
}
};
Additional customization can be done on the base Searchable class such as background and foreground color, keystrokes,
case sensitivity,
|
addTableSelection | protected void addTableSelection(JTable table, int rowIndex, int columnIndex, boolean incremental)(Code) | | Selects the cell at the specified row and column index. If incremental is true, the previous selection will not be cleared.
This method will use
JTable.changeSelection(intintbooleanboolean) method to select the cell
if the row and column index is in the range and the cell was not selected. The last two parameters of changeSelection
is true and false respectively.
Parameters: table - the table Parameters: rowIndex - the row index of the cell. Parameters: columnIndex - the column index of the cell Parameters: incremental - false to clear all previous selection. True to keep the previous selection. |
getElementCount | protected int getElementCount()(Code) | | |
getMainIndex | public int getMainIndex()(Code) | | Gets the index of the column to be searched.
the index of the column to be searched. |
getSelectedIndex | protected int getSelectedIndex()(Code) | | Gets the selected index.
the selected index. |
isColumnSelectionAllowed | protected boolean isColumnSelectionAllowed(JTable table)(Code) | | Is the column selection allowed?
Parameters: table - the table. true if the table is the column selection. |
isFindPreviousKey | protected boolean isFindPreviousKey(KeyEvent e)(Code) | | |
isRowSelectionAllowed | protected boolean isRowSelectionAllowed(JTable table)(Code) | | Is the row selection allowed?
Parameters: table - the table. true if the table is the row selection. |
isSelectedCellEditable | protected boolean isSelectedCellEditable()(Code) | | Checks if the selected cell is editable. If yes, we will not activate Searchable when key is typed.
true if the selected cell is editable. |
setMainIndex | public void setMainIndex(int mainIndex)(Code) | | Sets the main index. Main index is the column index which you want to be searched.
Parameters: mainIndex - the index of the column to be searched. If -1, all columns will be searched. |
setSelectedIndex | protected void setSelectedIndex(int index, boolean incremental)(Code) | | |
uninstallListeners | public void uninstallListeners()(Code) | | |
|
|