Question: This is a sample of the code that I am using to instantiate a JFrame:

```
public class TestFrame{
public static void main(String[] args){
    JFrame frame = new JFrame();
    Insets insets = frame.getInsets();
    frame.setSize(new Dimension(insets.right + insets.left + 400, insets.bottom + insets.top + 400));
    System.out.println(String.format("Top = %d \nBottom = %d \nLeft = %d \n Right
            = %d", insets.top, insets.bottom, insets.left, insets.right));

    frame.setResizable(false);
    frame.setVisible(true);
}
}

```

The frame is displaying fine but all of the insets seem to be equal to zero. I need to know the size of the title bar on top because I want a Content Pane of size 400x400 exactly.

I tested it on multiple platforms and the same thing happens on windows and on mac.

What am I doing wrong ?

Answer: 
If contentPane should be exactly 400 x 400, then create a class that retuns this for its preferredSize and use it as the contentPane:

```
class MyContentPane extends JPanel {
   public static final int PREF_W = 400;
   public static final int PREF_H = 400;

   public Dimension getPreferredSize() {
     return new Dimension(PREF_W, PREF_H);
   }
}

```

or perhaps better:

```
class MyContentPane extends JPanel {
   public int prefW;
   public int prefH;

public MyContentPane(int prefW, int prefH) {
   this.prefW = prefW;
   this.prefH = prefH;
}

   public Dimension getPreferredSize() {
     return new Dimension(prefW, prefH);
   }
}

```

As mentioned by the other posters, you'll have to use `pack()` on the top level window and use layout managers.

Myself I prefer not to do this but to rather let the actual preferred sizes of various compoennts and the container's layout managers do all of this deciding for me.
You are misunderstanding what you are working with, so it will seem "wrong".

Insets are not the dimensions of the "stuff" outside of the content pane. They are similar to a "border" around the content pane, where drawing will not be allowed to occur. Unlike borders, insets do not overlap.

The size of the decoration *around* the window is not determined by the program. It is determined by a different program, that handles focus, and window navigation. That program is called the *window manager*. It is the window manager that handles the "title bar on top" and it's height, font, etc. 

To get an "exact size" program, you need to ask the window manager for a frame-less window, which can be done in Java. It will not have a title bar on top, nor will it have resizing handles near the edges, the window command menu, the red "x" to close, or a means for moving the window across your desktop (although your program can reposition itself if written to do so). 

An alternative is to request an exclusive "screen" in the proper dimensions and root pane window, which was sometimes done with games. It is a more restrictive way of doing things, and resolutions are limited to supported screen sizes.

In the event that you really wanted the content pane to be a particular size, and not the whole window to be a particular size, please look to the other excellent answers that deal with a content pane's preferred size.