Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private JPanel panel;
- private JTable productsTable;
- private JScrollPane scrollPaneProducts;
- public SearchAllProductsGUI(){
- c = new GridBagConstraints();
- panel = new JPanel(new BorderLayout());
- panel.setPreferredSize(new Dimension(500,500));
- panel.setBackground(Color.lightGray);
- panel.setVisible(true);
- apli = ApplicationLogic.getInstance();
- List<Ware> allProducts = null;
- allProducts = apli.findAllProducts();
- String columnNames[] = { "Product ID", "Product Name", "Amount" ,"Expire Date", "isDeleted" , "isFood" ,"Preis"};
- String[][] matrix = new String[allProducts.size()][7];
- int count = 0;
- for(Ware w : allProducts) {
- matrix[count][0] = String.valueOf(w.getId());
- matrix[count][1] = w.getName();
- matrix[count][2] = String.valueOf(w.getLager());
- matrix[count][3] = w.getExpireDate();
- matrix[count][4] = (w.getIsDeleted() ? "Yes" : "No");
- matrix[count][5] = (w.getIsFood() ? "Yes" : "No");
- matrix[count][6] = "" + w.getPreis();
- count++;
- }
- productsTable = new JTable(matrix, columnNames);
- // Add the table to a scrolling pane
- // productsTable.setAutoResizeMode();
- productsTable.getColumnModel().getColumn(0).setPreferredWidth(75);
- productsTable.getColumnModel().getColumn(1).setPreferredWidth(160);
- productsTable.getColumnModel().getColumn(2).setPreferredWidth(35);
- productsTable.getColumnModel().getColumn(3).setPreferredWidth(120);
- productsTable.getColumnModel().getColumn(4).setPreferredWidth(45);
- productsTable.getColumnModel().getColumn(5).setPreferredWidth(55);
- productsTable.getColumnModel().getColumn(6).setPreferredWidth(55);
- productsTable.setAutoCreateRowSorter(true);
- productsTable.setEnabled(false);
- if(scrollPaneProducts == null){
- scrollPaneProducts = new JScrollPane(productsTable);
- panel.add(scrollPaneProducts);
- }else{
- panel.remove(scrollPaneProducts);
- scrollPaneProducts = new JScrollPane(productsTable);
- panel.add(scrollPaneProducts);
- }
- panel.revalidate();
- }
Add Comment
Please, Sign In to add comment