JFrame dimensions?

I want my next game to have a re sizable window (no external libraries used)

How do I get the size of the interior of the JFrame?
What I mean is, I can get the total width/height of the JFrame “frame” via “frame.getWidth()”

The problem is that I set the size of the frame to be 640 x 480, but when I get the dimensions via the method above, I get 646 x 509.

I can only imagine that the numbers get bigger because of the size of the border of the window.

But I don’t want those dimensions, I want the dimensions of what I’m actually drawing on.

I know I could just subtract 6 and 29, but that won’t work for every OS.

So how can I get the dimensions I’m looking for?

Thanks.

getInsets().

Though it’s less work (and probably more reliable) to draw onto a child Component (JPanel for instance), rather than directly onto the top-level Window.

So how could I get the width and height using the aforementioned frame.getWidth() and the “getInset()” method, because the only variables I see from the Inset are top, bottom, right, and left, and I don’t quite see how to use that information. I don’t quite understand what to add and subtract.

Thanks

Abuse’s second suggestion is the better approach. You’re rendering to some component you shove into a JFrame, such as a Canvas or JPanel. Use setPreferredSize(new Dimension(640, 480) to set the size of that component. Then your drawing surface is 640x480, and you don’t have to care about the window’s frame size.

On resize events, just grab the new size of the Canvas or JPanel you’re rendering on. Then you can decide whether to stretch your screens to fit, center them, etc.