1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/* Create AWT Label With Text Alignment Example This java example shows how to create a label and align label text using AWT Label class. */ import java.applet.Applet; import java.awt.Label; /* <applet code="CreateLableWithAlignment" width=100 height=200> </applet> */ public class CreateLableWithAlignment extends Applet{ public void init(){ /* * To create a label with it's text alignment use * Label(String text, int alignment) * constructor of AWT Label class. * * The possible alignment values are * Label.LEFT, Label.RIGHT, and Label.CENTER */ Label label1 = new Label("Left Aligned Label", Label.LEFT); Label label2 = new Label("Right Aligned Label", Label.RIGHT); Label label3 = new Label("Center Aligned Label", Label.CENTER); //add labels add(label1); add(label2); add(label3); /* * To change alignment of label's text use * void setAlignment(int alignment) * method of AWT Label class. */ Label label4 = new Label("Set Center Alignment"); add(label4); label4.setAlignment(Label.CENTER); } } |
Example Output
it has no effect in full screen