Label:
A label is a component which shows a single line of read-only, non-selectable text. It does not produce any special events. A label class declares three constructors
Label ( )
Label (String text)
Label (String text, int alignment)
The alignment of the label in a container could be specified through the following constants of the Label class. The default alignment of label is left.
public static final int LEFT
public static final int CENTER
public static final int RIGHT
The Label class declares accessor methods for reading the current text and modifying the text in a label:
String getText ( )
void setText(String text)
There are also accessor methods for reading the current alignment and setting a particular alignment for a label:
int getAlignment ( )
void setAlignment( int alignment)
Instance demonstrates two Labels, one along with default (left) alignment and another along with centered.
// Illustrating Labels
import java.awt.*;
import java.applet.*;
public class LabelApplet extends Applet
{
public void init ( )
{
setLayout(new GridLayout(2,1);
add(new Label("A sticky label");
add(new Label("One more sticky label", label.CENTER);
}
}