title: Declaring a JDialog that has already been created
body: <p>This question might not make any sense, because I am incredibly confused. I am creating a UI using Swing in Netbeans. I have created a Dialog box by using the Swing UI. I want to open this Dialog when I click on a button on the main Frame. In the Source Code it already declares my Dialog as a variable. When I try to use setVisible on this Dialog variable it on shows the top of the box, the title and an exit button, none of the buttons or text that I added to the Dialog box. I was told I had to declare this Dialog box, but is it not already declared by the automatically generated code?</p>
  <pre><code>public class ComputeUI extends javax.swing.JFrame {
  
      /**
       * Creates new form ComputeUI
       */
      public ComputeUI() {
          initComponents();
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings(&quot;unchecked&quot;)
      // &lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot;Generated Code&quot;&gt;                          
      private void initComponents() {
  
          GCDDialog = new javax.swing.JDialog();
          jPanel1 = new javax.swing.JPanel();
          jLabel5 = new javax.swing.JLabel();
          jButton3 = new javax.swing.JButton();
          jTextField2 = new javax.swing.JTextField();
          jLabel9 = new javax.swing.JLabel();
          jLabel10 = new javax.swing.JLabel();
          
          jLabel2 = new javax.swing.JLabel();
          jLabel7 = new javax.swing.JLabel();
          jButton2 = new javax.swing.JButton();
          jTextField1 = new javax.swing.JTextField();
          jLabel8 = new javax.swing.JLabel();
          jMenuBar1 = new javax.swing.JMenuBar();
          jMenu1 = new javax.swing.JMenu();
          jMenuItem2 = new javax.swing.JMenuItem();
          jMenu2 = new javax.swing.JMenu();
          jMenuItem1 = new javax.swing.JMenuItem();
          
  
          GCDDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
          GCDDialog.setTitle(&quot;GCD&quot;);
          GCDDialog.setAlwaysOnTop(true);
          GCDDialog.setLocationByPlatform(true);
          GCDDialog.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
          GCDDialog.setName(&quot;GCDDialog&quot;); // NOI18N
  
          jLabel5.setText(&quot;Number:&quot;);
  
          jButton3.setText(&quot;Compute&quot;);
  
          
  
          javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
          jPanel1.setLayout(jPanel1Layout);
          jPanel1Layout.setHorizontalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addGap(20, 20, 20)
                          .addComponent(jLabel5)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addContainerGap()
                          .addComponent(jButton3))
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addContainerGap()
                          .addComponent(jLabel9)
                          .addGap(18, 18, 18)
                          .addComponent(jLabel10)))
                  .addContainerGap(171, Short.MAX_VALUE))
          );
          jPanel1Layout.setVerticalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addGap(22, 22, 22)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jLabel5)
                      .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(25, 25, 25)
                  .addComponent(jButton3)
                  .addGap(33, 33, 33)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jLabel9)
                      .addComponent(jLabel10))
                  .addContainerGap(71, Short.MAX_VALUE))
          );
  
          javax.swing.GroupLayout GCDDialogLayout = new javax.swing.GroupLayout(GCDDialog.getContentPane());
          GCDDialog.getContentPane().setLayout(GCDDialogLayout);
          GCDDialogLayout.setHorizontalGroup(
              GCDDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          );
          GCDDialogLayout.setVerticalGroup(
              GCDDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(GCDDialogLayout.createSequentialGroup()
                  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(0, 0, Short.MAX_VALUE))
          );
  
          GCDDialog.getAccessibleContext().setAccessibleName(&quot;GCDDialog&quot;);
  
  
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          jMenu1.setText(&quot;File&quot;);
  
          jMenuItem2.setText(&quot;Exit&quot;);
          jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jMenuItem2ActionPerformed(evt);
              }
          });
          jMenu1.add(jMenuItem2);
  
          jMenuBar1.add(jMenu1);
  
          jMenu2.setText(&quot;Compute&quot;);
  
          jMenuItem1.setText(&quot;GCD&quot;);
          jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jMenuItem1ActionPerformed(evt);
              }
          });
          jMenu2.add(jMenuItem1);
  
          
          
  
          jMenuBar1.add(jMenu2);
  
          setJMenuBar(jMenuBar1);
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 400, Short.MAX_VALUE)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 279, Short.MAX_VALUE)
          );
  
          pack();
      }// &lt;/editor-fold&gt;                        
  
      private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
          // TODO add your handling code here:
          System.exit(0);
      }                                          
  
      private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
          // TODO add your handling code here:
          GCDDialog.setVisible(true);
      }                                          
  
      /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //&lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot; Look and feel setting code (optional) &quot;&gt;
          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
           */
          try {
              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                  if (&quot;Nimbus&quot;.equals(info.getName())) {
                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
                      break;
                  }
              }
          } catch (ClassNotFoundException ex) {
              java.util.logging.Logger.getLogger(ComputeUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(ComputeUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(ComputeUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(ComputeUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          //&lt;/editor-fold&gt;
  
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new ComputeUI().setVisible(true);
              }
          });
      }
  
      // Variables declaration - do not modify                     
      
      private javax.swing.JDialog GCDDialog;
      private javax.swing.JButton jButton2;
      private javax.swing.JButton jButton3;
      private javax.swing.JLabel jLabel10;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JLabel jLabel5;
      private javax.swing.JLabel jLabel7;
      private javax.swing.JLabel jLabel8;
      private javax.swing.JLabel jLabel9;
      private javax.swing.JMenu jMenu1;
      private javax.swing.JMenu jMenu2;
      private javax.swing.JMenuBar jMenuBar1;
      private javax.swing.JMenuItem jMenuItem1;
      private javax.swing.JMenuItem jMenuItem2;
      
      private javax.swing.JPanel jPanel1;
      private javax.swing.JTextField jTextField1;
      private javax.swing.JTextField jTextField2;
      // End of variables declaration                   
  } 
  </code></pre>