title: Dynamically growing JPanel with BoxLayout (on a null layout)
body: <p>I have a JPanel with a vertical BoxLayout on top of a JPanel with a null layout.</p>
  
  <p>I would like the JPanel with the BoxLayout to grow as the components are being added. </p>
  
  <p>See this code:</p>
  
  <pre><code>public static void main (String[] args) {
      JFrame f = new JFrame();
      f.setSize(500,500);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel total = new JPanel();
      total.setLayout(null);
      total.setSize(f.getWidth(),f.getHeight());
      total.setBackground(Color.green);
      JPanel box = new JPanel();
      box.setLocation(100,200);
      box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
      box.add(new JButton("test"));
      box.add(new JLabel("hey"));
      total.add(box);
      f.add(total);
      f.setVisible(true);
  }
  </code></pre>
  
  <p>You will notice that no components show up.</p>
  
  <p>How can I make the JPanel "box" such that the size dynamically increases as I add more components (which are added vertically).</p>
  
  <p>IN ADVANCE: I need the position of "box" to be at exactly 100,200 so please do not suggest that I do not use null layout. I must use null layout. The null layout of "total" should not effect the answer to my question, which focuses on the "box" panel.</p>