JFrame : Getting actual content size

此生再无相见时 提交于 2019-12-01 00:48:54

问题


I have created a JFrame, and attempting to get it's size is giving an incorrect result, compared to what I expect.

I have determined that it is including the operating system borders around the edges, and the title bar.

How can I get/set the real size which I have available for rendering?


回答1:


The size you are getting is the size of the content and the size of the insets. If you use Jcomponent.getInsets(), you can find the size of the content with simple subtraction.




回答2:


Your question is confusing: JPanels don't have title bars or window borders, they are abstract containers that are INSIDE JFrames. JFrames are the objects with title bars and window borders.

JPanel.getSize() should work as intended. However, for JFrames you'll want to use JFrame.getContentPane().getSize(), because getContentPane() returns the JPanel (which is the actual content area).



来源:https://stackoverflow.com/questions/7154633/jframe-getting-actual-content-size

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