title: NetBeans & Swing - dynamically add JPanel to JDialog
body: <p>I am designing an application in NetBeans, as illustrated in the screenshot below.</p>
  
  <p><img src="https://i.stack.imgur.com/3vvbh.png" alt="enter image description here"></p>
  
  <p>When the user clicks on a JButton on a JFrame, a JDialog pops-up asking the user to enter a numeric value using a numeric keypad. I would like the JDialog to dynamically add 2 JPanels. JPanel 1 will contain a textbox for input. JPanel 2 will contain a numeric keypad. I designed them this way so that I could reuse the numeric keypad whenever I need it. The problem I am facing is displaying dynamically these 2 JPanels on the JDialog that pops-up. JDialog pops-up empty. Please take a look at my code below. Thank you all, I appreciate your help</p>
  
  <p><strong>This is the sample code of JDialog:</strong></p>
  
  <pre><code>public class MyDialog extends javax.swing.JDialog {
  
      public MyDialog(java.awt.Frame parent, boolean modal) {
          super(parent, modal);
          initComponents();
  
          SwingUtilities.invokeLater(new Runnable() {
  
              @Override
              public void run() {//Add JPanel 2 (Numeric Keypad) to JDialog
                  Container contentPane = getContentPane();
                  NumericKeypadPanel nkp = new NumericKeypadPanel();
                  nkp.setLayout(new java.awt.BorderLayout());
                  contentPane.removeAll();
                  contentPane.add(nkp);
                  contentPane.validate();
                  contentPane.repaint();
              }
          });
      }
  </code></pre>
  
  <p><strong>This is the sample code for JPanel 2 (Numeric Keypad):</strong></p>
  
  <pre><code>public class NumericKeypadPanel extends javax.swing.JPanel {
  
      /** Creates new form NumericKeypadPanel */
      public NumericKeypadPanel() {
          initComponents();//Draws 10 number buttons
      }
  }
  </code></pre>