0

I have a simple library application, and one thing it needs to accomplish is checkout/return books. In that checkout/return window, I have two tables, a "Book List" table, which starts full of books I already have stored, and a "Checkout/Return" table, which starts out empty. The Checkout/Return table is populated by double clicking items in the Book List table, and then depopulated by double clicking items displayed within itself. Double clicking adds or removes the book items to/from a checkout/return ArrayList (which is then displayed in the table).

What I'm looking for is a way to filter out books in the Book List table by the contents of the Checkout/Return ArrayList. (Unable to post images of desired effect at this time).

Is this even possible, and if so, how similar is this to filtering by the contents of a JTextField?

Edit: I've since found this approach: http://pulkitsinghal.blogspot.com/2010/06/multiple-row-filters-for-jtable.html.

RowFilter<TableModel, Object> firstFiler = null;
RowFilter<TableModel, Object> secondFilter = null;
List<RowFilter<TableModel,Object>> filters = new ArrayList<RowFilter<TableModel,Object>>();
RowFilter<TableModel, Object> compoundRowFilter = null;
try {
    firstFiler = RowFilter.regexFilter(yourRegexString, columnIndex);
    secondFilter = RowFilter.regexFilter(yourRegexString, columnIndex);
    filters.add(firstFiler);
    filters.add(secondFilter);
    compoundRowFilter = RowFilter.andFilter(filters); // you may also choose the OR filter
} catch (java.util.regex.PatternSyntaxException e) {
    return;
}
sorter.setRowFilter(compoundRowFilter);

However, this achieves the opposite affect I want. Rather than filtering out everything that doesn't match the filter input, I want to filter out everything that does match the filter input.

pmackni
  • 307
  • 3
  • 12
  • Start with [How to use tables](https://docs.oracle.com/javase/tutorial/uiswing/components/table.html) and look for the section on sorting and filtering – MadProgrammer Apr 07 '15 at 21:46
  • For [example](http://stackoverflow.com/questions/13255282/jtable-sort-rows-based-on-attribute-not-in-table/13258555#13258555). What I might do, is place a (hidden) field in your book class which flags the book as borrowed or not, this would be more efficient when it comes to filtering it – MadProgrammer Apr 07 '15 at 21:52

0 Answers0