title: Java JLabel text in middle of vertical axis
body: <p>I have a <code>JLabel</code> that contains variable text in a certain location in my GUI.  The problem is that the text gets displayed at the bottom of the space where the <code>JLabel</code> is located. This does not convey to the end user the relevant information about the other contents of the GUI. Instead, I need the text of the <code>JLabel</code> to be printed in the middle of the vertical axis of the <code>JLabel</code>.  A simplified version of my code is below. Can anyone show me how to alter it so that the text displays in the middle of the vertical axis instead of the bottom?</p>
  
  <p>Main.java:</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  
  public class Main {
      public static void main(String[] args) {
          JFrame frame = new JFrame("Main");      
          frame.getContentPane().setLayout(new FlowLayout());
          frame.getContentPane().add(new VerticalLabel("Hello"));
          Dimension prefSize = new Dimension(400, 300);
          frame.setPreferredSize(prefSize);
          frame.setMinimumSize(prefSize);
          frame.pack();
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>VerticalLabel.java:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import javax.swing.border.EtchedBorder;
  
  public class VerticalLabel extends JLabel {
      public VerticalLabel(String labelText) {
          Dimension myDim = new Dimension(15, 250);
          this.setPreferredSize(myDim);
          this.setHorizontalAlignment(LEFT);
          this.setVerticalAlignment(CENTER);
          this.setText(labelText);
          this.setVerticalTextPosition(CENTER);
          this.setUI(new VerticalLabelUI(false));
          this.setBorder(new EtchedBorder());
      }
  }
  </code></pre>