简体   繁体   中英

JTable custom RowFilter?

RowFilter examples only do text comparison, but how does one filter rows that are linked to particular properties ?

my datamodel class

class MyDataModel
{
    private ArrayList<MyFile> data; // for the rows data 

...

class Myfile
{
   private boolean error; // file name issues
   private boolean ignored; // file ignored for process
   private boolean exception; // file processed no matter other conditions
...

so how do I filter the rows where the MyFile has some property to true (or even more complex tests on these fields)

thanks

What do you mean by text comparision? Have you added your filter and overridden include method?

boolean include(RowFilter.Entry<? extends M,? extends I> entry) 

The API document here RowFilter itself explains how you can filter based on integer/number or based on any property type

    RowFilter<Object,Object> filter = new RowFilter<Object,Object>() 
    {
       public boolean include(Entry<? extends Object, ? extends Object> entry) 
       {
           int rowID=(Integer)entry.getIdentifier();
           FilesTableModel data=(FilesTableModel) entry.getModel();
           return data.isVisible(rowID);
       }
    };
    TableRowSorter<FilesTableModel> sorter = new TableRowSorter<FilesTableModel>(data);
    sorter.setRowFilter(filter);
    table.setRowSorter(sorter);

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