Jtable过滤以搜索一系列数据

时间:2015-03-25 09:40:21

标签: java filter jtable datefilter

我有两个文本字段,我提供过滤数据的输入。我无法搜索数据。

      String c=DATE.getText();
      String d=DATE2.getText();

      DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
      Date D1 = null;

    try {
        D1 = format.parse(c);
    } 
    catch (ParseException ex) {
        Logger.getLogger(ECN320_C.class.getName()).log(Level.SEVERE, null,ex);
    }

     Date D2 = null;
    try {

        D2 = format.parse(d);
    } 
    catch (ParseException ex) {
        Logger.getLogger(ECN320_C.class.getName()).log(Level.SEVERE, null, ex);
    }


   DefaultTableModel model =(DefaultTableModel)TABLE1.getModel(); 
   JTable table = new JTable(model);
   table.setAutoCreateRowSorter(true);

   TableRowSorter<TableModel> sorter = new TableRowSorter<>(TABLE1.getModel());
       TABLE1.setRowSorter(sorter); 

   try
   {
   RowFilter<TableModel, Integer> low =    RowFilter.dateFilter(RowFilter.ComparisonType.AFTER,D1, 5);

   RowFilter<TableModel, Integer> high = RowFilter.dateFilter(RowFilter.ComparisonType.BEFORE,D2, 5);

   java.util.List <RowFilter<TableModel, Integer>> filters = Arrays.asList(low, high);

   final RowFilter<TableModel, Integer> filter =    RowFilter.andFilter(filters);

   sorter.setRowFilter(filter);
   }
   catch(Exception e){}

0 个答案:

没有答案