title: How do I align components in Java Swing?
body: <p>I'm building a simple beginner app in Java and I need your help with aligning components. What I'm trying to do is to align component(JLabel "name") to the left side of the panel. I've already tried with "new FlowLayout(FlowLayout.LEFT)" but it didn't work so I'm asking you to help me. Here is the picture of the frame and source code below it.</p>
  
  <pre><code>public class firstClass extends JFrame implements ActionListener {
  
  
  private JFrame frame1;
  private JFrame frame2;
  private JPanel mainPanelFirst;
  private JPanel secondPanel;
  private JButton newWindowButton;
  private int mulitplyPanels;
  private JLabel leftLabel;
  private JLabel rightLabel;
  private JComboBox leftCB;
  private JComboBox rightCB;
  </code></pre>
  
  <p>First Window:</p>
  
  <p><a href="https://i.stack.imgur.com/DhXXM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DhXXM.png" alt="https://i.stack.imgur.com/DhXXM.png"></a></p>
  
  <pre><code>public JFrame createMainUI(){
  
     frame1 = new JFrame("Main frame");
     frame1.setSize(600,600);
     frame1.setResizable(false);
     frame1.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     frame1.setVisible(true);
  
     mainPanelFirst = new JPanel();
     mainPanelFirst.setLayout(new FlowLayout());
     frame1.add(mainPanelFirst);
  
  
     newWindowButton = new JButton("Open new window");
     newWindowButton.addActionListener(this);
     mainPanelFirst.add(newWindowButton);
  
  
     return frame1;
  </code></pre>
  
  <p>}</p>
  
  <p>Second Window(include the label I want to align):</p>
  
  <p><a href="https://i.stack.imgur.com/VRIFr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VRIFr.png" alt="https://i.stack.imgur.com/VRIFr.png"></a></p>
  
  <pre><code> public JFrame createSecondUI() {
  
      frame2 = new JFrame("Second frame");
      frame2.setSize(600, 600);
      frame2.setResizable(false);
      frame2.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      frame2.setVisible(true);
  
      secondPanel = new JPanel();
      secondPanel.setLayout(new FlowLayout());
      secondPanel.setBackground(Color.gray);
      frame2.add(secondPanel);
  
  
      JPanel topPanel = new JPanel();
      topPanel.setLayout(new FlowLayout(70,400,20));
      topPanel.setBackground(Color.WHITE);
      secondPanel.add(topPanel);
  
  
  
      leftLabel = new JLabel("Name:");
      topPanel.add(leftLabel);
  
  
  
      return frame2;
  
  
  }
  
  
   @Override
      public void actionPerformed(ActionEvent e) {
  
          createSecondUI();
  
      }
  }
  </code></pre>
  
  <p>Thank you for your help :)</p>