任何正文请随时帮助我,如何在Mac上集中JFrame. OS X?
我试过了:
<code>this.setLocationRelativeto(null); this.setLocationRelativeto(this); this.setLocationRelativeto(getRootPane()); </code>
..和
<code> 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);
</code>
以上都没有工作,我的框架仍然在底部并隐藏在Mac底座后面.
解决方法:
打包框架后应设置位置(计算框架的大小).
之后它应该是可见的(默认情况下它是隐藏的).
<code> pack(); setLocationRelativeTo(null); setVisible(true); </code>
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!