title: Make a JLabel text vertically aligned to the center
body: <p>How do I make a <code>JLabel</code> text vertically and horizontally aligned to the center?</p>
  
  <p>I have to make use of <code>setHorizontalTextPosition</code> and <code>setVerticalTextPosition</code>. Can this be achieved by using these 2? </p>
  
  <p>I have tried but the text remains at the top itself.</p>
  
  <pre><code> import java.awt.FlowLayout;
   import javax.swing.JFrame;
   import javax.swing.JLabel;
   import javax.swing.SwingConstants;
  
  public class label extends JFrame
  {
    private JLabel label;
  
      public label() //constructor
      {
        super("Simple GUI");
        setLayout(new FlowLayout());
  
        label=new JLabel("Centered JLabel");
        label.setHorizontalTextPosition(SwingConstants.CENTER);
        label.setVerticalTextPosition(SwingConstants.CENTER);
        add(label);
      }
   }
  </code></pre>