title: How to surround Java Swing components with border?
body: <p>I'm building an application which will consist of few tabbed panels. On each of them, I'd like to put sets of components separated from each other by borders. It would look like:</p>
  
  <pre><code>|- Titled Border 1 ---
  
  [JTextField] [JComboBox] [JTextField] [JComboBox]
  
  |--------
  
  |- Titled Border 2 ---
  
  [JTextField] [JComboBox] [JTextField] [JComboBox]
  
  |--------
  
  ... and so forth.
  </code></pre>
  
  <p>When I tried to simply add new border, Titled Border 2, to the panel, it was added and covered the first one leaving components on top though. In some examples I saw many JPanels defined within one frame and each panel had its own border. It might work in my case but how to add these panels to be displayed within one tab?</p>
  
  <p>One of Oracle's tutorials shows exactly a tabbed pane with demo of many kinds of borders. When I tried to edit it and put a component there, it appeared between two borders instead of being surrounded. And it was another option that was unsuccessful for me.</p>
  
  <p>Second thing is, I don't use any layout manager, components positions are fixed and honestly I would keep this setting. Or maybe you recommend using any layout manager in this specific case?</p>
  
  <p>Would you have any hints on how to solve this problem?</p>
  
  <p>Edit: it seems I'm not allowed yet to attach a screenshot, but here's the part of code taking care of displaying the borders:</p>
  
  <pre><code>    lenMicro = new JPanel();
      lenMicro.setLayout(null);
  
      bGreyLine = BorderFactory.createLineBorder(Color.GRAY, 1, true);
      bTitled1 = BorderFactory.createTitledBorder(bGreyLine, "Length (1/2)", TitledBorder.LEFT, TitledBorder.TOP);
      lenMicro.setBorder(bTitled1);
      bTitled2 = BorderFactory.createTitledBorder(bGreyLine, "Length (2/2)", TitledBorder.LEFT, TitledBorder.TOP);
      lenMicro.setBorder(bTitled2); 
  </code></pre>
  
  <p>The border titled "Length (2/2)" is displayed when the last two lines are uncommented.</p>