Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.Label extends java.awt.Component { // Fields public final static int CENTER; public final static int LEFT; public final static int RIGHT; // Constructors public Label(); public Label(String label); public Label(String label, int alignment); // Methods public void addNotify(); public int getAlignment(); public String getText(); protected String paramString(); public void setAlignment(int alignment); public void setText(String label); }
A label is a component for placing text in a container. The text can be changed by the application, but a user cannot edit it directly.(1)
For example, the code:
setLayout(new FlowLayout(FlowLayout.CENTER,10,10)); add(new Label("Hi There!")); add(new Label("Another Label"));
produces the following:
public final static int CENTERIndicates that the label should be centered.
public final static int LEFTIndicates that the label should be left justified.
public final static int RIGHTIndicates that the label should be right justified.
public Label()Constructs an empty label with whose text is left justified.
public Label(String label)Constructs a new label with the specified string of text left justified.
Parameter Description label the text that makes up the label
public Label(String label, int alignment)Constructs a new label with the specified string of text and the specified alignment.
The alignment value must be one of Label.LEFT, Label.RIGHT, or Label.CENTER.
Parameter Description label the string that makes up the label alignment the alignment value
public void addNotify()This method calls the createLabel method of this object's toolkit in order to create a LabelPeer for this label. This peer allows the application to change the look of a label without changing its functionality.
Most applications do not call this method directly.
Overrides:
addNotify in class Component .
public int getAlignment()Return Value:
Returns the current alignment of this label.
See Also: setAlignment .
public String getText()Return Value:
Returns the text of this label.
See Also: setText .
protected String paramString()Returns the parameter string representing the state of this label. This string is useful for debugging.
Return Value:
Returns the parameter string of this label.
Overrides:
paramString in class Component .
public void setAlignment(int alignment)Sets the alignment for this label to the specified alignment.
Parameter Description alignment the alignment value Throw:
If an improper alignment was given.
See Also: getAlignment .
public void setText(String label)Sets the text for this label to the specified text.
Parameter Description label the text that makes up the label See Also: getText .
(1)In Java 1.0, the AWT does not send mouse, keyboard, or focus events to a label. In Java 1.1, the AWT sends to the label all mouse, keyboard, and focus events that occur over it.