public class java.awt
Label


Show All Login
Java SE 6
  
Extends: Component
Implements: Accessible
Inner classes: Label.AccessibleAWTLabel
Details
A Label object is a component for placing text in a container. A label displays a single line of read-only text. The text can be changed by the application, but a user cannot edit it directly.

For example, the code . . .


 setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
 add(new Label("Hi There!"));
 add(new Label("Another Label"));
 

produces the following labels:

Two labels: 'Hi There!' and 'Another label'
version1.59, 04/07/06
sinceJDK1.0


Fields
final public static int LEFT
Indicates that the label should be left justified.
final public static int CENTER
Indicates that the label should be centered.
final public static int RIGHT Details
Indicates that the label should be right justified.
sinceJDK1.0t.

Constructors
public Label() throws HeadlessException Details
Constructs an empty label. The text of the label is the empty string "".
ThrowsHeadlessException: if GraphicsEnvironment.isHeadless() returns true.
See also isHeadless
public Label(String text) throws HeadlessException Details
Constructs a new label with the specified string of text, left justified.
textthe string that the label presents. A null value will be accepted without causing a NullPointerException to be thrown.
ThrowsHeadlessException: if GraphicsEnvironment.isHeadless() returns true.
See also isHeadless
public Label(String text, int alignment) throws HeadlessException Details
Constructs a new label that presents the specified string of text with the specified alignment. Possible values for alignment are Label.LEFT, Label.RIGHT, and Label.CENTER.
textthe string that the label presents. A null value will be accepted without causing a NullPointerException to be thrown.
alignmentthe alignment value.
ThrowsHeadlessException: if GraphicsEnvironment.isHeadless() returns true.
See also isHeadless

Methods
public void addNotify()
Creates the peer for this label. The peer allows us to modify the appearance of the label without changing its functionality.
protected String paramString() Details
Returns a string representing the state of this Label. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
returnthe parameter string of this label

Properties
public AccessibleContext getAccessibleContext() Details
Gets the AccessibleContext associated with this Label. For labels, the AccessibleContext takes the form of an AccessibleAWTLabel. A new AccessibleAWTLabel instance is created if necessary.
returnan AccessibleAWTLabel that serves as the AccessibleContext of this Label
since1.3
public void setAlignment(int alignment) Details
Sets the alignment for this label to the specified alignment. Possible values are Label.LEFT, Label.RIGHT, and Label.CENTER.
alignmentthe alignment to be set.
ThrowsIllegalArgumentException: if an improper value for alignment is given.
See also getAlignment
public int getAlignment() Details
Gets the current alignment of this label. Possible values are Label.LEFT, Label.RIGHT, and Label.CENTER.
See also setAlignment
public void setText(String text) Details
Sets the text for this label to the specified text.
textthe text that this label displays. If text is null, it is treated for display purposes like an empty string "".
See also getText
public String getText() Details
Gets the text of this label.
returnthe text of this label, or null if the text has been set to null.
See also setText