Results 1 to 2 of 2
  1. #1
    d0n
    d0n is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

    Default Filtering JTables with multiply filters

    Hello Java Forum members,

    I want to create 2 filters, 1 filter that does a "or filtering" in column x and a "and filtering" over all rows.

    I have a combobox that can handle 2 values or more. Each combobox controles a column.



    So if u see my table example i want to filter on "Daniel" & "Gerrit" and on "Today".

    So the result should be:



    My problem is to join the andFilter and the orFilter.

    Java Code:
    public void setFilter( JTable tabel ){
            ArrayList filterNames = new ArrayList();
            ArrayList filterInhoud = null;
            final ArrayList totalList = new ArrayList();
           
            TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tabel.getModel());
            List<RowFilter<Object,Object>> filters = null;
           
    
            Iterator<String> itr = tableFilters.keySet().iterator();
            while(itr.hasNext()){
                filterNames.add(itr.next());
            }
    
            totalList.clear();
            for(int i = 0; i < filterNames.size(); i++ ){      
                filterInhoud = (ArrayList) tableFilters.get(filterNames.get(i));
                totalList.addAll(filterInhoud);
            }
    
            filters = new ArrayList<RowFilter<Object,Object>>(totalList.size());
    
            for( int i=0; i < totalList.size(); i++ ){
                filters.add( RowFilter.regexFilter(  "^"+((Filter)totalList.get(i)).getWaarde().toString()+"$"  , ((Filter)totalList.get(i)).getKolomnr() ) );
            }
            sorter.setRowFilter(RowFilter.andFilter(filters));
            tabel.setRowSorter(sorter);
    }
    The code above helps me with the combination of "Daniel" and "Today" but not when i try "Daniel" or "Gerrit" and "Today".

    I know i need to use the orFilter also, but i cant find a way to use it. So i was thinking of overriding the methode "include"

    Java Code:
    RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {
    
        @Override
        public boolean include(Entry<? extends Object, ? extends Object> entry) {
    
            return true;
        }
    };
    What u guys think i should do? Please help me here, im totaly stuck
    Last edited by d0n; 08-19-2011 at 03:33 PM.

  2. #2
    d0n
    d0n is offline Member
    Join Date
    Aug 2011
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Comboboxes and JTables
    By Hugo in forum AWT / Swing
    Replies: 4
    Last Post: 04-24-2011, 06:50 PM
  2. Jtables
    By amiral.smith in forum AWT / Swing
    Replies: 1
    Last Post: 01-28-2011, 03:22 PM
  3. matrix multiply
    By slixtrix in forum New To Java
    Replies: 8
    Last Post: 09-13-2010, 06:50 AM
  4. JTables and Databases
    By sehudson in forum Advanced Java
    Replies: 8
    Last Post: 03-25-2010, 09:01 AM
  5. CheckBoxes and JTables
    By lakshayghai in forum AWT / Swing
    Replies: 1
    Last Post: 03-16-2010, 08:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •