Java JTable Row Sort filt(ArrayList selectedLevel, String text, TableRowSorter sorter)

Here you can find the source of filt(ArrayList selectedLevel, String text, TableRowSorter sorter)

Description

filt

License

Apache License

Declaration

public static void filt(ArrayList<Integer> selectedLevel, String text, TableRowSorter<TableModel> sorter) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import javax.swing.RowFilter;

import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

public class Main {

    public static void filt(ArrayList<Integer> selectedLevel, String text, TableRowSorter<TableModel> sorter) {
        ArrayList<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(2);
        RowFilter<Object, Object> textFilter = null;
        RowFilter<Object, Object> levelFilter = null;

        if (text.length() != 0) {
            textFilter = RowFilter.regexFilter(text);
        }/*from w  w w  .  ja  va 2 s  .  c  om*/
        if (!selectedLevel.isEmpty()) {
            String levels = "[";
            for (Integer integer : selectedLevel) {
                levels += ((integer + 1) + "");
            }
            levels += "]";
            levelFilter = RowFilter.regexFilter(levels, 1);
        }
        if (levelFilter != null) {
            filters.add(levelFilter);
        }
        if (textFilter != null) {
            filters.add(textFilter);
        }
        sorter.setRowFilter(RowFilter.andFilter(filters));
    }
}

Related

  1. addSingleSortableColumnListener( @Nonnull RowSorter rowSorter)
  2. applyRowSorter(JTable table)
  3. createTableRowSorter(Class clazz, TableModel model)
  4. getSortOrder(@Nonnull RowSorter rowSorter, int column)
  5. jtable$setAutoCreateRowSorter(JTable table)
  6. setSortOrder(@Nonnull RowSorter rowSorter, int column, @Nonnull SortOrder sortOrder)
  7. tryToEnableRowSorting(JTable listTbl)