title: How to Dynamically Add JButton to JPanel?
body: <p>In NetBeans, I have used the GUI editor to make a JFrame and I've put a JPanel in the frame.
  At the moment, I'm trying to make a new button in the panel when the class constructs.
  This is the code I have, but I can't seem to get it to work.
  (The first line makes the button, the other lines try to show it.)</p>
  
  <pre><code>this.jPanel2.add(new JButton("Test"),BorderLayout.NORTH);
  this.jPanel2.validate();
  this.jPanel2.revalidate();
  this.jPanel2.repaint();
  this.jPanel2.setVisible(true);
  this.revalidate();
  this.setVisible(true);
  this.repaint();
  </code></pre>
  
  <p>I've been googling all night, but can't seem to get it to work.</p>