[SWINGX-1349] Patch for setRowFilter() method in JXTable Created: 27/Sep/10  Updated: 28/Jan/11  Resolved: 01/Nov/10

Status: Resolved
Project: swingx
Component/s: Table
Affects Version/s: 1.6.2
Fix Version/s: 1.6.3

Type: Task Priority: Trivial
Reporter: cronid Assignee: kleopatra
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All
URL: http://forums.java.net/jive/thread.jspa?threadID=153486&tstart=0


Issuezilla Id: 1,349

 Description   

At the moment it is only possible to use "TableModel" as generic parameter in
"setFilter(RowFilter<? super TableModel, ? super Integer> filter)".

e.g.

DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
JXTable table = new JXTable(model);
table.setAutoCreateRowSorter(true);
RowFilter<DefaultTableModel, Integer> filter = RowFilter.regexFilter("240", 1);
table.setRowFilter(filter); // error

wont work, because of this error:
The method setRowFilter(RowFilter<? super TableModel,? super Integer>) in the
type JXTable is not applicable for the arguments
(RowFilter<DefaultTableModel,Integer>)

In JTable to set a RowFilter, you use an instance of TableRowSorter<M extends
TableModel> where "setRowFilter(RowFilter<? super M, I super Integer> filter)"
is given. That means the first generic parameter has to be a "? super M extends
TableModel" type. To do this directly in JXTable, you can use this way:

public <R extends TableModel> void setFilter(RowFilter<? super R, ? super
Integer> filter) {
if (hasSortController())

{ // all fine, because R is a TableModel (R extends TableModel) SortController<R> sorter = (SortController<R>) getSortController(); sorter.setRowFilter(filter); }

else {
// no sort controller
if (getRowSorter() instanceof DefaultRowSorter<?, ?>)

{ // all fine, because R is a TableModel (R extends TableModel) DefaultRowSorter<R, Integer> sorter = (DefaultRowSorter<R, Integer>) getRowSorter(); sorter.setRowFilter(filter); }

}
}

For an example see
http://forums.java.net/jive/thread.jspa?threadID=153486&tstart=0 (for JTable and
JXTable)

That issue may address all other swingx components with "setRowFilter()" as well.



 Comments   
Comment by kleopatra [ 06/Oct/10 ]

applied the patch (slightly changed) to JXTable/JXList

the slight change is to do nothing if the hasSortController is false: JXTable guarantees
to not touch the RowSorter if it can't do it completely

Comment by kleopatra [ 06/Oct/10 ]

.

Generated at Sat Aug 29 18:12:45 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.