title: Unwanted border around JPanel
body: <p>I'm creating a form with a JPanel inside it for some graphics and some buttons for controlling the thing. For some reason I have to specify the JPanel to be 10 px less wide and 30 px less high than the actual graphics I want to put inside it. What causes this problem?</p>
  
  <p>This is the code:</p>
  
  <pre><code>public class Window {
   public Sheepness sheepness;
  
   public ButtonPanel buttonPanel;
   public PaintPanel paintPanel;
   public JFrame frame;
  
   public Window(Sheepness sheepness) {
    this.sheepness = sheepness;
  
    frame = new JFrame("Sheepness simulation");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //frame.setSize(width, height);
  
    BorderLayout frameLayout = new BorderLayout();
    JPanel background = new JPanel(frameLayout);
    background.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  
    buttonPanel = new ButtonPanel(this);
    background.add(BorderLayout.SOUTH, buttonPanel.buttonBox);
  
    paintPanel = new PaintPanel(this);
    paintPanel.setPreferredSize(new Dimension(320, 240));
    background.add(BorderLayout.CENTER, paintPanel);
  
    frame.getContentPane().add(background);
    frame.pack();
    frame.setResizable(false);
    frame.setVisible(true);
   }
  }
  
  public class PaintPanel extends JPanel {
   public Window window;
  
   public PaintPanel(Window window) {
    this.window = window;
   }
  
   @Override
   public void paintComponent(Graphics g) {
    g.setColor(Color.blue);
    g.fillRect(0, 0, 320, 240);
   }
  }</code></pre>
  
  <p>Screenshot with a preferredSize of 320 x 240:</p>
  
  <p><a href="http://www.cmbi.ru.nl/~estens/Sheepness/Sheepness_simulation_border.png" rel="nofollow noreferrer">Can&#39;t find source image http://www.cmbi.ru.nl/~estens/Sheepness/Sheepness_simulation_border.png</a>.</p>
  
  <p>You can see the 320 x 240 fillRect doesn't fill the JPanel entirely, a border of 10 px width and 30 px height remains.</p>
  
  <p>Screenshot with a preferredSize of 310 x 210:</p>
  
  <p><a href="http://www.cmbi.ru.nl/~estens/Sheepness/Sheepness_simulation_noBorder.png" rel="nofollow noreferrer">Can&#39;t find source image http://www.cmbi.ru.nl/~estens/Sheepness/Sheepness_simulation_noBorder.png</a>.</p>
  
  <p>Now it fits the 320 x 240 fillRect exactly!</p>
  
  <p>Any ideas?</p>