My JFrame always becomes a few pixels too big.

自闭症网瘾萝莉.ら 提交于 2019-11-28 14:05:36

This is an issue related to using setResizable(false); AFTER you've tried setting the size of the window.

The problem is that (on Windows at least), the size of the frames border is different between resizable and non-resizable windows.

Call setResizable before calling pack

If you want a better (and generally more reliable) way to center your window, consider using

setLocationRelativeTo(null);

instead of

setLocation(s.width/2-getWidth()/2, s.height/2-getHeight()/2);

Toolkit.getScreenSize doesn't take into consideration the space taken up by the task bar...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!