HugEnuf

How to insert specific lines to jTable

Aug 27th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. So I have a file named Order.txt. Below are the info inside the text file.
  2.  
  3. Order ID:Item ID:Item Name:Item Price:Qty:Total Price:User ID:Status:
  4. 0:3:mee goreng:7.00:1:7.0:TP054120:Processing:
  5. 1:3:mee goreng:7.00:1:7.0:TP054120:Processing:
  6. 2:2:fried rice:8.00:1:8.0:TP054120:Processing:
  7. 3:3:mee goreng:7.00:1:7.0:TP054120:Pending:
  8.  
  9. I am trying to insert line where Status == "Processing" only. But I dont know how to do it. I have done my code but it insert all of the lines to jTable.
  10.  
  11. try{
  12. try (FileReader odR = new FileReader(od); BufferedReader odBR = new BufferedReader(odR)) {
  13. String [] colHeaders = odBR.readLine().trim().split(":");
  14.  
  15. DefaultTableModel model = (DefaultTableModel) tbOrder.getModel();
  16. model.setColumnIdentifiers(colHeaders);
  17. model.setRowCount(0);
  18.  
  19. Object[] tableLines = odBR.lines().toArray();
  20.  
  21. for (Object tableLine : tableLines) {
  22. String line = tableLine.toString().trim();
  23. String[] row = line.split(":");
  24. model.addRow(row);
  25. }
  26. }
  27. }catch (IOException ex) {
  28. Logger.getLogger(manageMenu.class.getName()).log(Level.SEVERE, null, ex);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment