title: How to open a jdialog from a jframe
body: <p>JFrame button to open the jdialog:</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      // TODO add your handling code here:
  </code></pre>
  
  <p>JDialog method that opens the dialog:</p>
  
  <pre><code>        public void run() {
              AddClient dialog = new AddClient(new javax.swing.JFrame(), true);
              dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                  @Override
                  public void windowClosing(java.awt.event.WindowEvent e) {
                      System.exit(0);
                  }
              });
              dialog.setVisible(true);
  </code></pre>
  
  <p>My JDialog class is named AddClient, my JFrame class is named MainWindow. The package these are in is named my.javaapp</p>
  
  <p>How would i go onto doing this? I'm pretty new to java, was using python up until this point and dove head in into java swing gui builder with netbeans, i'm planning on watching tutorials and reading through the java documentation to learn more about java, but i would like to start by being able to open this jdialog.</p>
  
  <p><em>Before asking this question i searched a lot, and i read other questions that had been asked to solve more or less this same problem, i still couldn't solve mine though so i'm asking.</em></p>
  
  <p><strong>Solution:</strong></p>
  
  <p>Delete the main function from the class the gui you want to pop up is on e.g</p>
  
  <pre><code>public static void main(String args[]) {
  
      try {
          for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  javax.swing.UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (ClassNotFoundException ex) {
          java.util.logging.Logger.getLogger(NewJDialog1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
          java.util.logging.Logger.getLogger(NewJDialog1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
          java.util.logging.Logger.getLogger(NewJDialog1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (javax.swing.UnsupportedLookAndFeelException ex) {
          java.util.logging.Logger.getLogger(NewJDialog1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      }
      //&lt;/editor-fold&gt;
  
      /* Create and display the dialog */
      java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
              NewJDialog1 dialog = new NewJDialog1(new javax.swing.JFrame(), true);
              dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                  @Override
                  public void windowClosing(java.awt.event.WindowEvent e) {
                      System.exit(0);
                  }
              });
              dialog.setVisible(true);
          }
      });
  }
  </code></pre>
  
  <p>Before deleting though, copy this line:</p>
  
  <pre><code>NewJDialog1 dialog = new NewJDialog1(new javax.swing.JFrame(), true);
  </code></pre>
  
  <p>Right click the button you want to pop this window up after pressing, events > action > action performed. Paste it there like this:</p>
  
  <pre><code>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  
  NewJDialog1 dialog = new NewJDialog1(new javax.swing.JFrame(), true); 
  
  dialog.setVisible(true);
  
  }
  </code></pre>
  
  <p>Remember to add the last line, that's what shows up the dialog.</p>