title: How do I position and size JLabels in Java?
body: <p>I want to be able to position my two JLabels but when I change the values in the position lines it does nothing. Also when I run it only the second label is displayed.</p>
  
  <p>My code:</p>
  
  <pre><code>import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.SwingConstants;
  
  public class cubeTimerClass {
  
      public static void main(String[] args) {
          window(); //Runs the window method
      }
  
      public static void window() {
          //Create a window
                  JFrame window = new JFrame(); //Create the window object
                  window.setSize(900, 600); //Set the size of the window
                  window.setTitle("Cube Timer"); //Set the title of the window
                  window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Tells the program to quit when user closes the window
                  window.setVisible(true); //Make the window visible
  
                  //Create a label
                  JLabel label1 = new JLabel(""); //Create the label1 object
                  label1.setText("Message 1"); //Set the text for label1
                  label1.setAlignmentX(0);
                  label1.setAlignmentY(0);
                  window.add(label1); //Place the label on the window
  
                  //Create a label
                  JLabel label2 = new JLabel(""); //Create the label2 object
                  label2.setText("Message 2"); //Set the text for label2
                  label2.setAlignmentX(0);
                  label2.setAlignmentY(50);
                  window.add(label2); //Place the label on the window
      }
  }
  </code></pre>