Java:JFrame.setLocationRelativeTo(null)不以Ubuntu 10.04 / g
发布时间:2020-12-15 00:25:43 所属栏目:Java 来源:网络整理
导读:示例代码: JFrame jFrame = new JFrame("Test"); jFrame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE); jFrame.setLocationRelativeTo(null); jFrame.setSize(600,600); jFrame.pack(); // jFrame.setLocationRelativeTo(null); // same results jFrame
示例代码:
JFrame jFrame = new JFrame("Test"); jFrame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE); jFrame.setLocationRelativeTo(null); jFrame.setSize(600,600); jFrame.pack(); // jFrame.setLocationRelativeTo(null); // same results jFrame.setVisible(true); screenshot http://img193.imageshack.us/img193/5296/screenshotrev.png 这是OpenJDK的错吗?我记得听说它不如Sun的那么好,但由于它成为Ubuntu的标准,或者我决定与之配合使用的标准.该程序可能会在windows上运行,所以我想我要检查那里…任何简单的方法来解决这个在平台独立的方式,而不会破坏它已经工作的地方? 解决方法
一种方法是手动定位窗口.在打电话给pack()之后放置以下代码.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Point middle = new Point(screenSize.width / 2,screenSize.height / 2); Point newLocation = new Point(middle.x - (jFrame.getWidth() / 2),middle.y - (jFrame.getHeight() / 2)); jFrame.setLocation(newLocation); 免责声明,这只是在Windows上测试. 此外,您应该始终使用setPreferredSize()而不是setSize(). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |