title: Adding multiple JPanels to a JFrame in real time
body: <p>I am writing a tool take performs a task on text file. The task takes some time to perform so I made a panel that displays the file name and the progress in percentage.
  The user may run the task on one or on several files, so I need to display a panel for each file. The problem is that the panels are not being added. <strong>I am updating my code to be self contained as suggested below</strong>:</p>
  
  <pre><code>package sscce.jpanel;
  
  import javax.swing.JFrame;
  import javax.swing.JTextArea;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.logging.Logger;
  import javax.swing.JButton;
  import javax.swing.BoxLayout;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.SwingConstants;
  
  public class FProgressDisplay extends JFrame {
      private final static Logger LOGGER = Logger.getLogger(FProgressDisplay.class.getName());
      private List&lt;PanelTaskProgress&gt; tasks;
      JTextArea txtLog;
      JButton btnAbort;
      JButton btnClose;
  
  
      public static void main(String[] args) {
          try {
              FProgressDisplay frame = new FProgressDisplay();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
  
              for(int i = 0; i &lt; 10; i++) {
                  frame.addTask(i, "Task"+i);
              }
  
          } catch (Exception e) {
              e.printStackTrace();
              throw new RuntimeException("Failed to initialize application.");
          }
      }
      /**
       * Create the frame.
       */
      public FProgressDisplay() {
          setTitle("Mask tool - Progress");
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          pack();
          getContentPane().setLayout(null);
          getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
  
          JPanel panel = new JPanel();
          getContentPane().add(panel);
  
          btnAbort = new JButton("Abort");
          panel.add(btnAbort);
  
          btnClose = new JButton("Close");
          panel.add(btnClose);
  
          txtLog = new JTextArea();
          txtLog.setLineWrap(true);
          getContentPane().add(txtLog);
  
          tasks = new ArrayList&lt;PanelTaskProgress&gt;();
      }
  
      public void addTask(long id, String fileName) {
          PanelTaskProgress newTaskPanel = new PanelTaskProgress(id, fileName);
          tasks.add(newTaskPanel);
          getContentPane().add(newTaskPanel);
          validate();
          repaint();
          LOGGER.info("Added new panel");
      }
  
      public class PanelTaskProgress extends JPanel {
          private static final long serialVersionUID = 1L;
          JLabel lblTaskDescription;
          JLabel lblProgress;
          private long id;
          /**
           * Create the panel.
           */
          public PanelTaskProgress(long id, String fileName) {
              try {
                  setLayout(null);
  
                  lblTaskDescription = new JLabel(id + " " + fileName);
                  //lblTaskDescription.setBounds(10, 11, 632, 14);
                  add(lblTaskDescription);
  
                  lblProgress = new JLabel("0%");
                  lblProgress.setHorizontalAlignment(SwingConstants.CENTER);
                  //lblProgress.setBounds(664, 11, 51, 14);
                  add(lblProgress);
  
                  LOGGER.info("Created new panel; Id: " + id + "; File: " + fileName);
              } catch (Exception e) {
                  LOGGER.severe("Error creating new panel; " + e.getMessage());
              }
          }
      }
  }
  </code></pre>