The JXTable
from the SwingX project has a method to set a RowFilter
directly on the JXTable
(see JXTable#setRowFilter
).
It is unclear to me what you need to do when the filter implementation is dynamic.
To compare: in the JDK they introduced the RowSorter
interface in JDK1.6, and this interface allows to attach a RowSorterListener
. If you have a dynamic RowSorter
(which can also be used for filtering), you can fire an event to those listeners when the filter changes (although this requires that the filter has access to the RowSorter
as there is no such thing as a DynamicRowFilter
or RowFilterEvent
in the JDK).
What I would expect is that I can set an "observable" RowFilter
on the JXTable
and that I have to do nothing. But as that seems not to be possible with the current API, what is the next best thing ?
JXTable
?setRowFilter
method and create your own TableRowSorter
and fall back on the JDK API.The use-case we have is a filter (not a rowfilter) which can be changed to filter out elements of a model, and we have a RowFilter based on that dynamic filter to filter out those elements
Repeating my comment: the RowFilter must be immutable. That was a concious design decision back when sorting/filtering was introduced into core. So the approach to implement "dynamic" filtering is to
Edit
I don't agree with that design, but couldn't sway him
should be: I didn't agree - meanwhile, I'm not so sure as I had been ;-)
The advantage of this approach is that the RowFilter is really small coin to implement and highly re-usable - just a simple predicate, nothing else. That allows simple logic compounding (and/or) of filters. No burden to notify on part of the filter, no burden on part of the sorter (or compound filter) to listen and update itself. Then taking into account that the "dynamics" of the filter change often comes from user interaction and something has to listen to those user triggers anyway, it's not a big deal to create a new rowFilter vs. updating an existing rowFilter.