title: How to check if a JFrame is open by checking it's one of the components are visible
body: <p>I have this code sample in a separate <code>jDialog</code> (<code>jDialog</code> is in the same package as that of <code>JFrame</code>) which used to check (using a <code>Thread</code>) if the <code>jCheckBox1</code> in the <code>jFrame</code> is whether visible or not. <code>JDialog</code> is set to visible by clicking a <code>JLabel</code> (<strong>Change Password</strong>) in <code>JFrame</code>. I have not set the visibility of the <code>JFrame</code> even to <code>false</code> even after I click on the <strong>Change Password</strong> <code>JLabel</code>. </p>
  
  <p>The problem I encountered is that even if the <code>JFrame</code> is <strong>not visible</strong> i.e when I run the <code>JDialog</code> separately (without clicking on the <strong>Change Password</strong> <code>JLabel</code>) it prints the <strong>"Visible"</strong> and I'm more than sure that the <code>jFrame</code> is not visible and not running. </p>
  
  <p>This is the code snippet (<code>Thread</code>) I have used to check the visibility of the <code>JFrame</code>'s <code>jCheckBox1</code>:</p>
  
  <pre><code>LockOptions lock = new LockOptions();
  
  private void setLocation2() {
      new Thread() {
          public void run() {
              boolean running = true;
              while (running) {
                  try {
                      Thread.sleep(1000);
                      if (lock.jCheckBox1.isVisible()) {
                          System.out.println("Visible");
                      } else {
                          System.out.println("Not Visible");
                      }
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
          }
      }.start();
  
  }
  </code></pre>
  
  <p>And this is the Code I have written in <code>JFrame</code>'s <strong>Change Password</strong> <code>JLabel</code>:</p>
  
  <pre><code>private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {                                     
  
      Container c = new ChangePassword(this, rootPaneCheckingEnabled);
  
      if (!c.isShowing()) {
          c.setVisible(true);
          hideMeToSystemTray();
          this.requestFocusInWindow();
      }
  
  } 
  </code></pre>
  
  <p>But when I run the <code>JDialog</code> separately (without clicking on the <strong>Change Password</strong> <code>JLabel</code>) it prints the <strong>"Visible"</strong></p>
  
  <p>I have attached a Screenshots of both <code>JFrame</code> and <code>JDialog</code></p>
  
  <p><code>JFrame</code> containing <code>jCheckBox1</code>
  <a href="https://i.stack.imgur.com/G9sVf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G9sVf.jpg" alt="JFrame"></a></p>
  
  <p><code>JDialog</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/6Kyld.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Kyld.jpg" alt="JDialog"></a></p>