Guest User

Untitled

a guest
Jul 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. private JPanel panel;
  2.     private JTable productsTable;
  3.     private JScrollPane scrollPaneProducts;
  4.    
  5.     public SearchAllProductsGUI(){
  6.  
  7.         c = new GridBagConstraints();
  8.        
  9.         panel = new JPanel(new BorderLayout());
  10.         panel.setPreferredSize(new Dimension(500,500));
  11.         panel.setBackground(Color.lightGray);
  12.         panel.setVisible(true);
  13.        
  14.         apli = ApplicationLogic.getInstance();
  15.         List<Ware> allProducts = null;
  16.         allProducts = apli.findAllProducts();
  17.        
  18.         String columnNames[] = { "Product ID", "Product Name", "Amount" ,"Expire Date", "isDeleted" , "isFood" ,"Preis"};
  19.         String[][] matrix = new String[allProducts.size()][7];
  20.        
  21.         int count = 0;
  22.  
  23.         for(Ware w : allProducts) {
  24.             matrix[count][0] = String.valueOf(w.getId());
  25.             matrix[count][1] = w.getName();
  26.             matrix[count][2] = String.valueOf(w.getLager());
  27.             matrix[count][3] = w.getExpireDate();
  28.             matrix[count][4] = (w.getIsDeleted() ? "Yes" : "No");
  29.             matrix[count][5] = (w.getIsFood() ? "Yes" : "No");
  30.             matrix[count][6] = "" + w.getPreis();
  31.             count++;
  32.         }
  33.        
  34.         productsTable = new JTable(matrix, columnNames);
  35.  
  36.         // Add the table to a scrolling pane
  37.  
  38. //      productsTable.setAutoResizeMode();
  39.         productsTable.getColumnModel().getColumn(0).setPreferredWidth(75);
  40.         productsTable.getColumnModel().getColumn(1).setPreferredWidth(160);
  41.         productsTable.getColumnModel().getColumn(2).setPreferredWidth(35);
  42.         productsTable.getColumnModel().getColumn(3).setPreferredWidth(120);
  43.         productsTable.getColumnModel().getColumn(4).setPreferredWidth(45);
  44.         productsTable.getColumnModel().getColumn(5).setPreferredWidth(55);
  45.         productsTable.getColumnModel().getColumn(6).setPreferredWidth(55);
  46.         productsTable.setAutoCreateRowSorter(true);
  47.         productsTable.setEnabled(false);
  48.  
  49.         if(scrollPaneProducts == null){
  50.             scrollPaneProducts = new JScrollPane(productsTable);
  51.             panel.add(scrollPaneProducts);
  52.         }else{
  53.             panel.remove(scrollPaneProducts);
  54.             scrollPaneProducts = new JScrollPane(productsTable);
  55.             panel.add(scrollPaneProducts);
  56.  
  57.         }
  58.  
  59.         panel.revalidate();
  60.        
  61.     }
Add Comment
Please, Sign In to add comment