java.awt

Class Label

public class Label extends Component implements Accessible

This component is used for displaying simple text strings that cannot be edited by the user.
Nested Class Summary
protected classLabel.AccessibleAWTLabel
This class provides accessibility support for the label.
Field Summary
static intCENTER
Alignment constant aligning the text in the center of its window.
static intLEFT
Alignment constant aligning the text to the left of its window.
static intRIGHT
Alignment constant aligning the text to the right of its window.
Constructor Summary
Label()
Initializes a new instance of Label with no text.
Label(String text)
Initializes a new instance of Label with the specified text that is aligned to the left.
Label(String text, int alignment)
Initializes a new instance of Label with the specified text and alignment.
Method Summary
voidaddNotify()
Notifies this label that it has been added to a container, causing the peer to be created.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this Label.
intgetAlignment()
Returns the constant indicating the alignment of the text in this label.
StringgetText()
Returns the text displayed in this label.
protected StringparamString()
Returns a parameter string useful for debugging.
voidsetAlignment(int alignment)
Sets the text alignment of this label to the specified value.
voidsetText(String text)
Sets the text in this label to the specified value.

Field Detail

CENTER

public static final int CENTER
Alignment constant aligning the text in the center of its window.

LEFT

public static final int LEFT
Alignment constant aligning the text to the left of its window.

RIGHT

public static final int RIGHT
Alignment constant aligning the text to the right of its window.

Constructor Detail

Label

public Label()
Initializes a new instance of Label with no text.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true.

Label

public Label(String text)
Initializes a new instance of Label with the specified text that is aligned to the left.

Parameters: text The text of the label.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true.

Label

public Label(String text, int alignment)
Initializes a new instance of Label with the specified text and alignment.

Parameters: text The text of the label. alignment The desired alignment for the text in this label, which must be one of LEFT, CENTER, or RIGHT.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true.

Method Detail

addNotify

public void addNotify()
Notifies this label that it has been added to a container, causing the peer to be created. This method is called internally by the AWT system.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Label. The context is created, if necessary.

Returns: the associated context

getAlignment

public int getAlignment()
Returns the constant indicating the alignment of the text in this label. The value returned will be one of the alignment constants from this class.

Returns: The alignment of the text in the label.

getText

public String getText()
Returns the text displayed in this label.

Returns: The text for this label.

paramString

protected String paramString()
Returns a parameter string useful for debugging.

Returns: A debugging string.

setAlignment

public void setAlignment(int alignment)
Sets the text alignment of this label to the specified value.

Parameters: alignment The desired alignment for the text in this label, which must be one of LEFT, CENTER, or RIGHT.

setText

public void setText(String text)
Sets the text in this label to the specified value.

Parameters: text The new text for this label.