过滤并搜索jtable netbeans

时间:2017-07-26 03:19:05

标签: java database netbeans jtable

我还是Java新手;我创建了一个搜索或过滤文本字段以在Jtable中查找我的数据库,但此代码仅搜索小写。如何进行可以过滤大写和小写的编码?

这是我的代码:

private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {   
   DefaultTableModel table = (DefaultTableModel)JTable_MosqueManagementSystem.getModel();
      String search = jTextField1.getText().toLowerCase();
    TableRowSorter<DefaultTableModel> tr = new TableRowSorter<DefaultTableModel>(table);
    JTable_MosqueManagementSystem.setRowSorter(tr);
    tr.setRowFilter(RowFilter.regexFilter(search)); }

2 个答案:

答案 0 :(得分:0)

通过从字符串中删除 toLowerCase()方法来尝试给定的模式

RowFilter<TableModel, Object> filter =    RowFilter.regexFilter(Pattern.compile(lookup,Pattern.CASE_INSENSITIVE).toString(),0,1);

如需进一步修改,请按照给定的链接

https://coderanch.com/t/498043/java/JTable-rowFilter-case-insensitive

答案 1 :(得分:0)

您可以通过此

更改最后一行
private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {   
   DefaultTableModel table = (DefaultTableModel)JTable_MosqueManagementSystem.getModel();
      String search = jTextField1.getText();
    TableRowSorter<DefaultTableModel> tr = new      TableRowSorter<DefaultTableModel>(table);
    JTable_MosqueManagementSystem.setRowSorter(tr);
    sorter.setRowFilter(RowFilter.regexFilter("(?i)" + "Alt",search));
 }

private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {   
           DefaultTableModel table = (DefaultTableModel)JTable_MosqueManagementSystem.getModel();
              String search = jTextField1.getText();
            TableRowSorter<DefaultTableModel> tr = new      TableRowSorter<DefaultTableModel>(table);
            JTable_MosqueManagementSystem.setRowSorter(tr);
        tr.setRowFilter(RowFilter.regexFilter("alt",Pattern.CASE_INSENSITIVE,search));
     }

或试试这个

private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {   
   DefaultTableModel table = (DefaultTableModel)JTable_MosqueManagementSystem.getModel();
      String search = jTextField1.getText();
    TableRowSorter<DefaultTableModel> tr = new      TableRowSorter<DefaultTableModel>(table);
    JTable_MosqueManagementSystem.setRowSorter(tr);
Pattern pattern = Pattern.compile("alt", Pattern.CASE_INSENSITIVE);
        tr.setRowFilter(RowFilter.regexFilter(pattern,search));
 }