title: Adding JPanel to Jframe dynamically
body: <p>I have a form on my Java application which basically is to provide the user with a list of data from a DB query. one idea was to use a table and populate each row with data from my resultset. However when designing the UI my team and i decided that it didnt look as smooth as we wanted. So we thought we would look into creating a custom view of the results in a panel. we wanted it to look something like:
  <img src="https://i.stack.imgur.com/lA1eP.jpg" alt="Desired custom view"></p>
  
  <p>So instead of rows of a table it will look like this with one for each enquiry on the resultset.</p>
  
  <p>The problem i am having is coding this. I spent a good deal of time trying to workout how to add a component to a JForm. as netbeans seem to by default set up the ui as a grouplayout? so I worked out how to add 1 panel using:</p>
  
  <pre><code>javax.swing.JLabel idLbl;
   javax.swing.JLabel jLabel1;
   javax.swing.JLabel jLabel3;
   javax.swing.JLabel jLabel5;
   javax.swing.JLabel jLabel7;
   javax.swing.JPanel jPanel1;
   javax.swing.JLabel prefContactLbl;
   javax.swing.JLabel propertyLabel;
      jPanel1 = new javax.swing.JPanel();
      jLabel1 = new javax.swing.JLabel();
      idLbl = new javax.swing.JLabel();
      jLabel3 = new javax.swing.JLabel();
      propertyLabel = new javax.swing.JLabel();
      jLabel5 = new javax.swing.JLabel();
      contactLabel = new javax.swing.JLabel();
      jLabel7 = new javax.swing.JLabel();
      prefContactLbl = new javax.swing.JLabel();
  
      jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  
      jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
      jLabel1.setText("Enquiry Id:");
      jLabel1.setName("jLabel"+i);
  
      idLbl.setText("jLabel2");
  
      jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
      jLabel3.setText("Property:");
  
      propertyLabel.setText("A property Address in some town with a postcode");
  
      jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
      jLabel5.setText("Contact:");
  
      contactLabel.setText("A Persons Name ( 01010100011)");
  
      jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
      jLabel7.setText("Prefered Contact:");
  
      prefContactLbl.setText("Email/Phone");
  
      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel1Layout.createSequentialGroup()
              .addContainerGap()
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addComponent(jLabel1)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(idLbl)
                      .addGap(18, 18, 18)
                      .addComponent(jLabel3)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(propertyLabel))
                  .addGroup(jPanel1Layout.createSequentialGroup()
                      .addComponent(jLabel7)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(prefContactLbl)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                      .addComponent(jLabel5)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(contactLabel)))
              .addContainerGap(20, Short.MAX_VALUE))
      );
      jPanel1Layout.setVerticalGroup(
          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel1Layout.createSequentialGroup()
              .addContainerGap()
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jLabel1)
                  .addComponent(idLbl)
                  .addComponent(jLabel3)
                  .addComponent(propertyLabel))
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jLabel7)
                  .addComponent(prefContactLbl)
                  .addComponent(jLabel5)
                  .addComponent(contactLabel))
              .addContainerGap())
      );
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(10 , 10, 10)
              .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addContainerGap(100, Short.MAX_VALUE))
      );
  
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addContainerGap()
              .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(570, Short.MAX_VALUE))
      );
  </code></pre>
  
  <p>The main problem I am faced is adding more than 1 dynamically I am completly unsure how to go about it as all i can find is to set the layout not update it. And I cant set how many .addcomponent as its dynamic. Really confused on how to go about this. </p>
  
  <p>Sorry if its hard to work out what I am trying to get across easier to think of it but putting it into words is a nightmare.</p>