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

Asg*_*har 3 java macos swing jframe

任何身体请帮助我,如何JFrame在Mac 上居中.OS X?

我试过了:

this.setLocationRelativeto(null);

this.setLocationRelativeto(this);
this.setLocationRelativeto(getRootPane());
Run Code Online (Sandbox Code Playgroud)

..和

    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);
Run Code Online (Sandbox Code Playgroud)

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

ygg*_*raa 8

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

 pack();
 setLocationRelativeTo(null);
 setVisible(true);
Run Code Online (Sandbox Code Playgroud)