JFrame: getting actual content size

I created a JFrame, and trying to get its size gives the wrong result compared to what I expect.

I determined that it includes the borders of the operating system along the edges and the title bar.

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

+7
source share
2 answers

The size you get 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 a simple subtraction.

+5
source

Your question is confused: JPanels do not have window headers or borders; they are abstract containers that are INSIDE JFrames. JFrames are objects with window headers and borders.

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

+2
source

All Articles