Java JFrame设置MAC OSX窗口中心的位置

Java JFrame设置MAC OSX窗口中心的位置,java,macos,swing,jframe,Java,Macos,Swing,Jframe,任何人都可以帮助我,如何在Mac上居中放置JFrame。OSX 我试过: this.setLocationRelativeto(null); this.setLocationRelativeto(this); this.setLocationRelativeto(getRootPane()); …及 final Toolkit toolkit = Toolkit.getDefaultToolkit(); final Dimension screenSize = toolkit

任何人都可以帮助我,如何在Mac上居中放置
JFrame
。OSX

我试过:

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 dock后面。

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

另见&。请注意,这两个答案都不涉及GUI在屏幕上居中。还有更好的选择。
 pack();
 setLocationRelativeTo(null);
 setVisible(true);