I am attempting to create a JInternalPane inside of the JDesktopPane but it is not centering correctly.
Here is how the JDesktopPane is created (I am using Netbeans drag-and-drop):
JDesktopPane desktopPane;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0, 0, screenSize.width / 2, screenSize.height / 2);
desktopPane = new JDesktopPane();
setContentPane(desktopPane);
I then create the JInternalFrame:
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) {}
I also set the preferred size of the JInternalFrame.
The login frame, however, appears in the top-left of the desktopPane, with most of it not visible (i.e. "outside" of the desktopPane).
I mostly followed this Java documentation. I also got the setLocation() information from this post as well as this post.
What am I doing wrong here that is causing the JInternalFrame to not be cenetered? Any help is appreciated.