title: Centering a JInternalFrame inside JDesktopPane not working correctly
body: <p>I am attempting to create a JInternalPane inside of the JDesktopPane but it is not centering correctly.</p>
  
  <p>Here is how the JDesktopPane is created (I am using Netbeans drag-and-drop):</p>
  
  <pre><code>JDesktopPane desktopPane;
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  setBounds(0, 0, screenSize.width / 2, screenSize.height / 2);
  desktopPane = new JDesktopPane();
  setContentPane(desktopPane);
  </code></pre>
  
  <p>I then create the JInternalFrame:</p>
  
  <pre><code>LoginUI login = new LoginUI();
  Dimension desktopSize = desktopPane.getSize();
  Dimension loginSize = login.getSize();
  int width = (desktopSize.width - loginSize.width) / 2;
  int height = (desktopSize.height - loginSize.height) / 2;
  login.setLocation(width, height);
  login.setVisible(true);
  desktopPane.add(login);
  try {
      login.setSelected(true);
  } catch (java.beans.PropertyVetoException e) {}
  </code></pre>
  
  <p>I also set the preferred size of the JInternalFrame.</p>
  
  <p>The login frame, however, appears in the top-left of the desktopPane, with most of it not visible (i.e. "outside" of the desktopPane).</p>
  
  <p>I mostly followed <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html" rel="nofollow noreferrer">this Java documentation</a>.
  I also got the setLocation() information from <a href="https://stackoverflow.com/questions/10046581/how-to-setvisible-a-jinternalframe-in-the-center-of-the-jdesktoppane">this post</a> as well as <a href="https://stackoverflow.com/questions/7488947/how-do-i-open-a-jinternalframe-centered-in-a-jdesktoppane">this post</a>.</p>
  
  <p>What am I doing wrong here that is causing the JInternalFrame to not be cenetered?  Any help is appreciated.</p>