title: JScrollPane doesn't update properly
body: <p>I have to insert new products in a JTable such that after pressing the "Add product" button, the table should update itself the new data provided. All the products are written into a file and read from it when printing out the table. The problem is that my table just stays the same and only after I exit the GUI application and enter again I can see the new updated JTable.</p>
  
  <p>Here's the relevant code from the GUI class: </p>
  
  <pre><code>private class ManageProductsListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
              ...
              addProductBtn.addActionListener(new AddProductListener());
              removeProductBtn.addActionListener(new RemoveProductListener());
              manageProductsPanel.add(warehouse);
              manageProductsPanel.setVisible(true);
              finalPanel.add(manageProductsPanel, BorderLayout.CENTER);
          }
      }
  
      private class AddProductListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
                  ...
                  manageProductsPanel.remove(warehouse);
                  Product product = new Product(insertProductName.getText(), Integer.parseInt(insertPrice.getText()), Integer.parseInt(insertStock.getText()));
                  warehouse.addProduct(product);
                  warehouse.writeFile();
                  warehouse.printProducts();
                  manageProductsPanel.add(warehouse);
                  ... 
          }
      }
  </code></pre>
  
  <p>And here's a part from the Warehouse class:</p>
  
  <pre><code>public class Warehouse extends JPanel {
      ...        
      private TreeSet&lt;Product&gt; products = new TreeSet&lt;Product&gt;();
      private JTable productsTable;
      private Object[][] data;
      private String[] columns = {"Product name", "Price", "In stock", "Understock", "Overstock"};
  
      public Warehouse() {
      }
  
      public void addProduct(Product newProduct) {
          products.add(newProduct);
      }
  
      public void writeFile() {
          try {
              FileOutputStream fos = new FileOutputStream("products.txt");
              ObjectOutputStream oos = new ObjectOutputStream(fos);
  
  
              Iterator&lt;Product&gt; i = products.iterator();
              while (i.hasNext()) {
                  oos.writeObject(i.next());
              }
              oos.close();
          } catch (IOException i) {
              i.printStackTrace();
          }
      }
  
      public void readFile() {
          ...
      }
  
      public void printProducts() {
          data = new Object[products.size()][5];
          Iterator&lt;Product&gt; iterator = products.iterator();
          int i = 0;
          while (iterator.hasNext()) {
              Product p = iterator.next();
              data[i][0] = p.getProductName();
              data[i][1] = p.getPrice();
              data[i][2] = p.getStock();
              data[i][3] = p.checkUnderstock();
              data[i][4] = p.checkOverstock();
              i++;
          }
          createTable();
      }
  
      public void createTable() {
          productsTable = new JTable(data, columns);
          productsTable.setPreferredScrollableViewportSize(new Dimension(600, 200));
          productsTable.setFillsViewportHeight(true);
          JScrollPane scroll = new JScrollPane(productsTable);
          add(scroll);
      }
  </code></pre>
  
  <p>Any help would be appreciated. Thanks in advance!</p>