title: JLabel alignment in JPanel
body: <p>I'm trying to align a JLabel to the right in a JPanel. I'm adding a JTabbedPane, a JPanel which contains my JLabel and JTextArea to a main JPanel. </p>
  
  <p>I have searched SO and tried some methods like <code>setAlignmentX</code>, <code>setHorizontalAlignment(SwingConstants.LEFT)</code> and nested containers to no avail. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  class LabelProblem
  
  {
  
   public static void main(String[] args)
  
   {
  
    JFrame frame = new JFrame("Label Problem");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
    JPanel Main = new JPanel();
    Main.setLayout(new BoxLayout(Main, BoxLayout.Y_AXIS));
  
    JPanel ComponentPanel = new JPanel();
    JLabel label = new JLabel("Sample Text");
    label.setHorizontalAlignment(SwingConstants.LEFT);
    label.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    label.setAlignmentX(Component.RIGHT_ALIGNMENT);
  
    ComponentPanel.add(label);
  
    JTabbedPane Tab = new JTabbedPane();
    Tab.add("Document 1", new JPanel());
  
    Main.add(Tab);
    Main.add(ComponentPanel);
  
    JTextArea Area = new JTextArea(10,10);
    JScrollPane Scroll = new JScrollPane(Area);
  
    frame.add(Main);
    frame.add(Scroll, BorderLayout.SOUTH);
    frame.setSize(450,450);
    frame.setVisible(true);
  
   }
  
  }
  </code></pre>
  
  <p>How can I align my JLabel to the right? </p>
  
  <p>Thanks! </p>