How to filter rows in JTable based on boolean valued columns?

Posted by vinny on Stack Overflow See other posts from Stack Overflow or by vinny
Published on 2010-04-08T23:57:46Z Indexed on 2010/04/09 0:03 UTC
Read the original article Hit count: 459

Filed under:
|
|

Im trying to filter rows based on a column say c1 that contains boolean values. I want to show only rows that have 'true' in c1. I looked up the examples in http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting. The example uses a regex filter. Is there any way I can use boolean values to filter rows?

Following is the code Im using (borrowed from the example)

private void filter(boolean show) {
  RowFilter<TableModel, Object> filter = null;
  TableModel model = jTb.getModel();
  boolean value = (Boolean) model.getValueAt(0,1);

    //If current expression doesn't parse, don't update.
    try {
         // I need to used  'value' to filter instead of filterText.
        filter =RowFilter.regexFilter(filterText, 0);
    } catch (java.util.regex.PatternSyntaxException e) {
        return;
    }
    sorter.setRowFilter(filter);

}

thank you.

© Stack Overflow or respective owner

Related posts about jtable

Related posts about filtering