title: setSize of JPanel after initialisation
body: <p>I am bringing in a ResultSet to show the contents of my table. thing is that though the results are showing i have been trying to resize the height of the JPanel so that it shows once it is populated. I tried using <code>setSize(300, y)</code> in the <code>while(ResultSet.next)</code> loop and also tried it outside of the loop. but nothing gives.<br>
  Here is my code:  </p>
  
  <pre><code>package SimpleCRUD;
  
  import java.awt.BorderLayout;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.Insets;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  
  @SuppressWarnings("serial")
  public class ShowContactsFrame extends JFrame {
      GridBagLayout layout = new GridBagLayout();
      GridBagConstraints Constraint = new GridBagConstraints();
      JLabel lblFname, lblLname, lblPhoneNumber;
      Statement st;
      String showAll = "SELECT * FROM `contacts`.`contacts`;";
      ResultSet rt;
      int y = 0;
  
      public ShowContactsFrame() {
          super("Contact List");
          try {
              AppCRUD initCRUD = new AppCRUD();
              rt = initCRUD.DBhandle.createStatement().executeQuery(showAll);
  
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
          setVisible(true);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          JPanel panel = new JPanel(layout);
          add(panel);
          getContentPane().add(panel, BorderLayout.NORTH);
  
          lblFname = new JLabel("lblFname");
          lblLname = new JLabel("lblLname");
          lblPhoneNumber = new JLabel("lblPhoneNumber");
  
          Insets inset = new Insets(10, 10, 10, 10);
  
          Constraint.insets = inset;
  
          try {
              while (rt.next()) {
                  Constraint.gridx = 0;
                  Constraint.gridy = y;
                  panel.add(new JLabel(rt.getString(2)), Constraint);
                  Constraint.gridx = 1;
                  Constraint.gridy = y;
                  panel.add(new JLabel(rt.getString(3)), Constraint);
                  Constraint.gridx = 2;
                  Constraint.gridy = y;
                  panel.add(new JLabel(rt.getString(4)), Constraint);
                  y++;
                  panel.setSize(300, y);
              }
  
          } catch (Exception ex) {
  
              ex.printStackTrace();
          }
          JOptionPane.showMessageDialog(null, y);
  
      }
  
  }
  </code></pre>