|
FilterHeaderModel |
Top Previous Next |
The abstract class FilterHeaderModel is used to provide real-time row filtering via a component that is installed on the table's header. Its subclasses need to implement methods to add this component on the column:
protected void removeRenderer(TableColumn aColumn);
protected void setRenderer(TableColumn aColumn);
PopupFilterHeaderModel, a FilterHeaderModel subclass, installs an arrow button on the column, which, when clicked, invokes a popup menu that contains available filter expression values regarding the column. Moreover, CustomPopupFilterHeaderModel adds a more complex custom filter.
You can use FilterHeaderModel in any JTable with either of the methods:
public void attachToTable(JTable table);
public void attachToTable(JTable table, FilterListModel flm);
FilterHeaderModel contains a specialized JTableHeader subclass, FilterTableHeader, which replaces the table's header upon calling the attachToTable method above. You can create, retrieve and assign the header with:
protected FilterTableHeader createTableHeader();
public FilterTableHeader getTableHeader();
public void setTableHeader(FilterTableHeader header);
Note: AdvancedJTable already provides a FilterTableHeader subclass, which must be assigned to FilterHeaderModel prior to calling the attachToTable method. (see example 2 below)
Example 1: Install a FilterHeaderModel on a JTable
//first create the FilterTableModel and JTable
ListTableModel unfilteredModel = new DefaultListTableModel();
FilterTableModel filteredModel = new FilterTableModel(unfilteredModel);
JTable table = new JTable(filteredModel);
//create the FilterHeaderModel
FilterHeaderModel fhm = new CustomPopupFilterHeaderModel();
//attach FilterHeaderModel to the table
fhm.attachToTable(table);
Example 2: Install a FilterHeaderModel on an AdvancedJTable
//first create the FilterTableModel and AdvancedJTable
ListTableModel unfilteredModel = new DefaultListTableModel();
FilterTableModel filteredModel = new FilterTableModel(unfilteredModel);
JTable table = new AdvancedJTable(filteredModel);
//create the FilterHeaderModel
FilterHeaderModel fhm = new CustomPopupFilterHeaderModel();
//assign AdvancedJTable's header to the FilterHeaderModel
fhm.setTableHeader((FilterTableHeader) table.getTableHeader());
//attach FilterHeaderModel to the table
fhm.attachToTable(table);