文本文件数据
01/Test1/1/Admin 02/Test2/1/Customer 03/Test3/1/Manager 04/Test4/1/Manager
以上是将数据存储在我的文本文件中的方式。
所以现在我想在jtable中显示数据,但是我只想要具有Manager选项的行。
下面是我的代码
DefaultTableModel table = (DefaultTableModel) jTable1.getModel();
try
{ String search3 = ManagerSearch.getText().toString();
TableRowSorter<DefaultTableModel> sort = new TableRowSorter<>(table);
jTable1.setRowSorter(sort);
sort.setRowFilter(RowFilter.regexFilter(search3));
BufferedReader br = new BufferedReader(new FileReader("managerinfo.txt"));
String reader;
while ((reader = br.readLine())!=null){
table.addRow(reader.split("\\|"));
}
br.close();
View.setEnabled(false);
Search.setEnabled(false);
}
catch (Exception e){
JOptionPane.showMessageDialog(null,e+" ");
}
答案 0 :(得分:0)
添加包含对读者的检查,如下所示:
DefaultTableModel table = (DefaultTableModel) jTable1.getModel();
try
{ String search3 = ManagerSearch.getText().toString();
TableRowSorter<DefaultTableModel> sort = new TableRowSorter<>(table);
jTable1.setRowSorter(sort);
sort.setRowFilter(RowFilter.regexFilter(search3));
BufferedReader br = new BufferedReader(new FileReader("managerinfo.txt"));
String reader;
while ((reader = br.readLine())!=null){
if(reader.contains("Manager")){
table.addRow(reader.split("\\|"));
}
}
br.close();
View.setEnabled(false);
Search.setEnabled(false);
}
catch (Exception e){
JOptionPane.showMessageDialog(null,e+" ");
}