If you don’t know what “AdjustWidowRect” does, here’s a description from MSDN:
Calculates the required size of the window rectangle, based on the desired client-rectangle size.
More clearly:
In swing, when you set the size of a JFrame, that includes the border. That means that if you set the size of the JFrame to 640 by 480, that will not be the client size, since the size you entered counts the size of the frames’ border.
I want to have a rectangle, and be able to adjust it so when the JFrame’s size is set to that rectangle, the client size of the JFrame is what the rectangle was before adjustment.
AFAIU the accepted answer does not account for menu bars or other components in the mix. This does, by overriding the preferred size of the component, and packing the frame.
Don’t paint to a top level container such as
JFrameorJWindow. Instead render to aJPanelorBufferedImageand add it to the TLC.