Reputation: 1983
I've created a jTable in which I create a column which is named "date". After entering 2 different dates in two jTextFields I want to show only the elements fromt the jTable that are in the given period of time. The date is formatted like this "YYYY-MM-DD".
Thanks for your help.
Upvotes: 0
Views: 1432
Reputation: 324128
Read the Swing tutorial on How to Use Tables. Read the secton on sorting and filtering which shows how to create a simple regexFilter.
I used the following code to modify the TableFilterDemo to create an "and" filter.
// rf = RowFilter.regexFilter(filterText.getText(), 0);
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter(filterText.getText(), 0));
filters.add(RowFilter.regexFilter(filterText.getText(), 1));
rf = RowFilter.andFilter(filters);
Once you understand the tutorial example and the usage of the "and filter" you can try to create your date filter.
Read the RowFilter API for information on how to create a dateFilter. Create a filter that displays rows after a certain date and create a filter that displays rows before a certain date. Once you get each of the filters working separatly you can then create an "and" filter.
Upvotes: 3