Skip to Main Content

Java SE (Java Platform, Standard Edition)


For appeals, questions and feedback, please email

How to Filter JTable Rows as Data Changes

871939Jun 28 2011 — edited Jun 29 2011

any helpful suggestions are welcome, I'm at a bit of a dead end at the moment.

So I have a JTable backed by a table model. The data in the table is liable to change while the system is running, when it does some events are raised. The table model listens for the appropriate events so that it can work out which row in the table needs to be updated, I can then call through to
int row = determineWhichRow( changedDataObject );
fireTableRowsUpdated( row, row );
This correctly causes the table row to update. Now the bit thats going wrong. The user is able to enable filters on the table, specifically on an attribute of the data in this table that changes. So when I fire the update event I need my row sorter (with the filters set) to re-sort the table. Having a look around there is a method on row sorter:
which from the javadoc I believed would create the behaviour I needed - assuming I told it to return true. Having tried this the functionality remains the same, as the data model changes, the values in the table update but the filters are not reapplied.

Debugging through the jdk code to get an idea of what might be going on it seems that the filters are called and it determines that the changed row should be filtered out, but gets to a point where it decides that because the event from the table model was an update event it shouldn't call a resize and repaint method and nothing further seems to happen.

I believe that simply re-setting the row sorter on the table would cause the desired effect but would be incredibly inefficient with a data model that can potentially change at any time. I can post the specific line numbers and jdk version if that is going to help anyone, but hopefully you'll all be able to give me an idea of what I might have missed.


This post has been answered by jduprez on Jun 29 2011
Jump to Answer
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 27 2011
Added on Jun 28 2011