mustangDC mustangDC - 1 year ago 204
Java Question

JTable rowfilter between two dates, same column

How can I implement a

between two dates? The dates are in string format. Is it necessary to change the format to a date format to apply a

I tried using the following, but failed :

DefaultTableModel model = (DefaultTableModel) easypath.masteBusiness_table.getModel();
TableRowSorter<TableModel> rowSorter = new TableRowSorter<>(easypath.masteBusiness_table.getModel());

I know I am wrong with the filtering as
is only for searching a single string but as a novice I would very much appreciate any suggestion.


I just saw this ( where
, M is the model and I is an integer value, which does not match my criteria

Answer Source

You should be storing a Date in the TableModel not a String representation of the date.

Then you can use a RowFilter.

Instead of a regex filter you can use an "and" filter with two date filters. Something like:

List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add( RowFilter.dateFilter(ComparisonType.AFTER, startDate) );
filters.add( RowFilter.dateFilter(ComparisonType.BEFORE, endDate) );
rf = RowFilter.andFilter(filters);

Read the Swing tutorial on Sorting and Filtering for more information and working examples on how to use a filter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download