Label
Name
Label
Description
The Label
is a Component
that displays a single line of static text.
Class Definition
public class java.awt.Label extends java.awt.Component { // Constants public static final int CENTER; public static final int LEFT; public static final int RIGHT; // Constructors public Label(); public Label (String label); public Label (String label, int alignment); // Instance Methods public void addNotify(); public int getAlignment(); public String getText(); public synchronized void setAlignment (int alignment); public synchronized void setText (String label); // Protected Instance Methods protected String paramString(); }
Constants
CENTER
public static final int CENTER
- Description
- Constant to center text within the label.
LEFT
public static final int LEFT
- Description
- Constant to left justify text within the label.
RIGHT
public static final int RIGHT
- Description
- Constant to right justify text within the label.
Constructors
Label
public Label()
- Description
- Constructs a
Label
object with the text centered within the label.
public Label (String label)
- Parameters
-
- label
- The text for the label
- Description
- Constructs a
Label
object with the textlabel
centered within the label.
public Label (String label, int alignment)
- Parameters
-
- label
- The text for the label
- alignment
- The alignment for the label; one of the constants
CENTER
,LEFT
, orRIGHT
.
- Throws
-
- IllegalArgumentException
- If alignment is not one of
CENTER
,LEFT
, orRIGHT
.
- Description
- Constructs a
Label
object, with a givenalignment
and text oflabel
.
Instance Methods
addNotify
public void addNotify()
- Overrides
Component.addNotify()
- Description
- Creates
Label
's peer.
getAlignment
public int getAlignment()
- Returns
- Current alignment.
getText
public String getText()
- Returns
- Current text of
Label
.
setAlignment
public synchronized void setAlignment (int alignment)
- Parameters
-
- alignment
- New alignment for
Label
;CENTER
,LEFT
, orRIGHT
.
- Throws
-
- IllegalArgumentException
- If
alignment
is not one ofCENTER
,LEFT
, orRIGHT
.
- Description
- Changes the current alignment of
Label
.
setText
public synchronized void setText (String label)
- Parameters
-
- label
- New text for
Label
.
- Description
- Changes the current text of
Label
.
Protected Instance Methods
paramString
protected String paramString()
- Returns
- String with current settings of
Label
. - Overrides
Component.paramString()
- Description
- Helper method for
toString()
to generate string of current settings.
See Also
Component
, String