Java JLabel get vertical alignment

Description

Java JLabel get vertical alignment


import javax.swing.JLabel;

public class Main {

  public void init() {
    JLabel label1 = new JLabel("demo2s.com");
    int alignment = label1.getVerticalAlignment();

    switch (alignment) {

    case JLabel.LEFT:
      label1.setText("Left");
      break;//w w w . j  av a 2s  . co  m
    case JLabel.CENTER:
      label1.setText("Center");
      break;
    case JLabel.RIGHT:
      label1.setText("Right");
      break;
    case JLabel.LEADING:
      label1.setText("Leading");
      break;
    case JLabel.TRAILING:
      label1.setText("Trailing");
      break;

    }

    label1.setVerticalAlignment(JLabel.CENTER);
  }
}



PreviousNext

Related