title: How to add padding to a JPanel with a border
body: <p>I want to add padding to some <code>JPanel</code>s. I found this answer: <a href="https://stackoverflow.com/a/5328475/1590323">https://stackoverflow.com/a/5328475/1590323</a></p>
  
  <p>It worked fine for a panel without a border. But how do I do it for a panel that already has a border? (A <code>TitledBorder</code> in this case)</p>
  
  <p>I tried:</p>
  
  <pre><code>JPanel mypanel = new MyPanel(); // Panel that I am going to add a TitledBorder to, but needs padding
  mypanel.setBorder(new EmptyBorder(10,10,10,10));
  JPanel mypanel_container = new JPanel();
  TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(), "My panel");
  border.setTitleJustification(TitledBorder.LEADING);
  mypanel_container.setBorder(border);
  mypanel_container.add(mypanel);
  this.add(mypanel_container);
  </code></pre>
  
  <p>(In short: Adding an <code>EmptyBorder</code> to the panel that should have a <code>TitledBorder</code>, then make another panel with the <code>TitledBorder</code> and add the first panel to that, and then use that panel)</p>
  
  <p>But then I got way too large padding that ignored the contructor values of the <code>EmptyBorder</code>.</p>
  
  <p>So <strong>how do I add padding to a JPanel with a graphical border?</strong></p>