I have a "Login internal frame" displayed while launching the application.But the problem is it does'nt appear centered in the screen of the application.
My code to get the actual size of the desktop and setting location of the JInternalFrame is as follows
private void new_init() {
LoginInternal login = new LoginInternal(jMenuBar1);
Dimension desktopSize = this.getSize();
Dimension jInternalFrameSize = login.getSize();
System.out.println("desktopSize: "+desktopSize+" jInternalFrameSize:" +jInternalFrameSize );
jMenuBar1.setVisible(false);
login.setLocation((desktopSize.width - jInternalFrameSize.width)/2,(desktopSize.height- jInternalFrameSize.height)/2);
jDesktopPane1.add(login);
login.show();
}
My screen resolution is 1366x768. But according to the print I have put
"desktopSize: java.awt.Dimension[width=1024,height=768] jInternalFrameSize:java.awt.Dimension[width=398,height=286]"
I get the resolution as 1024x768. In pre-init code of JDesktopPane,I have set "setExtendedState (JFrame.MAXIMIZED_BOTH);"
Now I get the both opened in maximised mode but the login frame is not centered as it takes the centering logic with resolution "[width=1024,height=768]".If it takes my current screen resolution I think it will be centered.
I hope i made it clear. Where iam going wrong?
The default size of a component is (0, 0) when it is created. Can't tell if your constructor code sets a size or not.
Don't use a JInternalFrame for this reason. Use a modal JDialog. The the basic code is: