简体   繁体   English

如何获得JDesktopPane也已最大化的Jframe的最大化大小?

[英]How to get the maximised size of the Jframe which has the JDesktopPane also maximized.?

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 我要获取桌面实际大小和JInternalFrame的设置位置的代码如下

private void new_init() { 私人无效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. 我的屏幕分辨率是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]" “ desktopSize:java.awt.Dimension [width = 1024,height = 768] jInternalFrameSize:java.awt.Dimension [width = 398,height = 286]”

I get the resolution as 1024x768. 我得到的分辨率为1024x768。 In pre-init code of JDesktopPane,I have set "setExtendedState (JFrame.MAXIMIZED_BOTH);" 在JDesktopPane的预初始化代码中,我设置了“ 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. 现在,我将两者都以最大化模式打开,但登录框未居中,因为它采用了分辨率为[[width = 1024,height = 768]”的居中逻辑。如果采用当前的屏幕分辨率,我认为它将居中。

I hope i made it clear. 我希望我说清楚了。 Where iam going wrong? 我哪里出问题了?

it does'nt appear centered in the screen of the application. 它不会出现在应用程序屏幕的中央。

LoginInternal login = new LoginInternal(jMenuBar1); 
Dimension desktopSize = this.getSize();
Dimension jInternalFrameSize = login.getSize();

The default size of a component is (0, 0) when it is created. 创建组件时,其默认大小为(0,0)。 Can't tell if your constructor code sets a size or not. 无法判断您的构造函数代码是否设置了大小。

I have a "Login internal frame" displayed while launching the application. 启动应用程序时,显示“登录内部框架”。

Don't use a JInternalFrame for this reason. 因此,请勿使用JInternalFrame。 Use a modal JDialog. 使用模式JDialog。 The the basic code is: 基本代码是:

JDialog dialog = new JDialog(...);
dialog.add(...);
dialog.pack();
dialog.setLocationRelativeTo( null );
dialog.setVisible( true );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM