繁体   English   中英

JFrame在MAC OSX上设置窗口中心的位置

[英]JFrame set location at center of window on MAC OSX

任何正文请随时帮助我,如何在Mac上集中JFrame OS X?

我努力了:

this.setLocationRelativeto(null);

this.setLocationRelativeto(this);
this.setLocationRelativeto(getRootPane());

..和

    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension screenSize = toolkit.getScreenSize();
    final int x = (screenSize.width - this.getWidth()) / 2;
    final int y = (screenSize.height - this.getHeight()) / 2;
    this.setLocation(x, y);

以上都没有工作,我的框架仍然在底部并隐藏在Mac底座后面。

打包框架后应设置位置(计算框架的大小)。 之后它应该是可见的(默认情况下它是隐藏的)。

 pack();
 setLocationRelativeTo(null);
 setVisible(true);

暂无
暂无

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

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