title: java - how to fix the "leaking this in constructor" warning
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3921616/java-leaking-this-in-constructor">Java - Leaking this in constructor</a>  </p>
  </blockquote>
  
  
  
  <p>In the NetBeans I have a JDialog that contains a JPanel. I am trying to pass a reference of the JDialog to the JPanel. Please take a look at my code below. When I do it the way I did I receive the "Leaking this in constructor" warning. I understand why, but I don't know how to fix this. I also know that I can use @SuppressWarnings("LeakingThisInConstructor") but isn't there a real way to fix this without suppressing the warning?</p>
  
  <pre><code>public class MyJDialog extends javax.swing.JDialog {
  
      public MyJDialog(java.awt.Frame parent, boolean modal) {
          super(parent, modal);
          initComponents();
          MyJPanel.getThis(this);
      }
  }
  
  public class MyJPanel extends javax.swing.JPanel {
  
      private JDialog dialog;
  
      public MyJPanel() {
          initComponents();
      }
  
      public void getThis(JDialog dialog){
          this.dialog = dialog;
      }
  }
  </code></pre>