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.
1. Make your ui in a panel.
2. Set the preferred size of the panel.
3. Add the panel to frame and call `pack()`