title: Java: vertical alignment within JPanel
body: <p>I am trying to vertically align (center) both JLabels inside one JPanel.</p>
  
  <pre><code>JPanel panel = new JPanel();
  panel.setPreferredSize(size);
  JLabel label1 = new JLabel(icon);
  JLabel label2 = new JLabel("text");
  panel.add(label1);
  panel.add(label2);
  </code></pre>
  
  <p>I have tried using setAligmentY() with no success. Both labels always appear on the top of JPanel.</p>
  
  <p>UPD: Labels should be located next to each other like using FlowLayout, but in the middle of the JPanel.</p>