JLabel: setVerticalTextPosition(int align) : JLabel « javax.swing « Java by API






JLabel: setVerticalTextPosition(int align)

 
import java.awt.GridLayout;

import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.plaf.metal.MetalIconFactory;

public class MainClass {

  public static void main(String args[]) {
    JFrame frame = new JFrame("Label Text Pos");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new GridLayout(2, 2));

    Border border = LineBorder.createGrayLineBorder();
    Icon warnIcon = MetalIconFactory.getTreeComputerIcon();

    JLabel label1 = new JLabel(warnIcon);
    label1.setText("Left-Bottom");
    label1.setHorizontalTextPosition(JLabel.LEFT);
    label1.setVerticalTextPosition(JLabel.BOTTOM);
    label1.setBorder(border);
    frame.add(label1);

    JLabel label2 = new JLabel(warnIcon);
    label2.setText("Right-TOP");
    label2.setHorizontalTextPosition(JLabel.RIGHT);
    label2.setVerticalTextPosition(JLabel.TOP);
    label2.setBorder(border);
    frame.add(label2);

    JLabel label3 = new JLabel(warnIcon);
    label3.setText("Center-Center");
    label3.setHorizontalTextPosition(JLabel.CENTER);
    label3.setVerticalTextPosition(JLabel.CENTER);
    label3.setBorder(border);
    frame.add(label3);

    JLabel label4 = new JLabel(warnIcon);
    label4.setText("Center-Bottom");
    label4.setHorizontalTextPosition(JLabel.CENTER);
    label4.setVerticalTextPosition(JLabel.BOTTOM);
    label4.setBorder(border);
    frame.add(label4);

    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}

           
         
  








Related examples in the same category

1.JLabel.BOTTOM
2.JLabel.CENTER
3.JLabel.LEFT
4.JLabel.RIGHT
5.JLabel.TOP
6.new JLabel(Icon icon)
7.new JLabel(Icon i, int alignment)
8.new JLabel(String htmlString) (Multi-line Label)
9.new JLabel(String text, int horizontalAlignment)
10.new JLabel(String text, Icon icon, int horizontalAlignment)
11.JLabel: addMouseMotionListener(MouseMotionListener l)
12.JLabel: getTransferHandler()
13.JLabel: setBoder(Border border)
14.JLabel: setBounds(int x, int y, int width, int height)
15.JLabel: setDisplayedMnemonic(int key) (KeyEvent.VK_U)
16.JLabel: setDisplayedMnemonicIndex(int index)
17.JLabel: setLabelFor(Component c)
18.JLabel: setText(String str)
19.JLabel: setHorizontalTextPosition(int align)
20.JLabel: setIcon(Icon icon)
21.JLabel: setOpaque(boolean isOpaque)
22.JLabel: setPreferredSize(Dimension preferredSize)
23.JLabel: setToolTipText(String text)
24.JLabel: setVerticalAlignment(int alignment)
25.extends JLabel