title: Java Swing packs the window wrong
body: <p>I'm making a Scorched Earth like game in Java (for my exam project :D), but I have this problem. I'm drawing a window (JFrame), setting layout to BorderLayout, applying an extended JPanel, and packing the window, but after it has been packed, it's showing some extended white space at the left and bottom border.</p>
  
  <p>This is my main class:</p>
  
  <pre><code>public class Main {
      public static void main(String[] args) {
          javax.swing.JFrame frame = new javax.swing.JFrame("game title");
          panel p = new panel(new java.awt.Dimension(512, 512));
          frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().setLayout(new java.awt.BorderLayout());
          frame.getContentPane().add(p, java.awt.BorderLayout.CENTER);
          frame.pack();
          frame.setResizable(false);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>panel is my JPanel class, which in the constructor is setting it's preferred size to the argument (512x512). I've tested this on both Windows and Linux, and the error it at both places, and the size of the white gap differs from OS to OS.</p>
  
  <p>This is my panel class:</p>
  
  <pre><code>class panel extends javax.swing.JPanel{
      panel(java.awt.Dimension size){
          setPreferredSize(size);
      }
      public void paint(java.awt.Graphics g){
          g.setColor(java.awt.Color.BLUE);
          g.fillRect(0, 0, 512, 512);
      }
  }
  </code></pre>
  
  <p>Please help!</p>