简体   繁体   中英

Show elements from jTable that are between two give dates

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM