title: How do I right align text within a JLabel?
body: <p>I have the following code:</p>
  
  <pre><code>JPanel panel = new JPanel();
  panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  
  for(int xx =0; xx &lt; 3; xx++)
  {
      JLabel label = new JLabel("String");
      label.setPreferredSize(new Dimension(300,15));
      label.setHorizontalAlignment(JLabel.RIGHT);
  
      panel.add(label);
  }
  </code></pre>
  
  <p>This is how I would like the text to look:</p>
  
  <pre><code>[                         String]
  [                         String]
  [                         String]
  </code></pre>
  
  <p>this is how it looks</p>
  
  <pre><code>[String]
  [String]
  [String]
  </code></pre>
  
  <p>For some reason label  doesn't get set to the preferred size I specified and I think because of this it doesn't right align my label text.  But im not sure.  Any help would be appreciated.</p>