Packages This Package Prev Next Index
§1.26 Class Label
public class java.awt.Label
extends java.awt.Component (II-§1.10)
{
// Fields
public final static int CENTER; §1.26.1
public final static int LEFT; §1.26.2
public final static int RIGHT; §1.26.3
// Constructors
public Label(); §1.26.4
public Label(String label); §1.26.5
public Label(String label, int alignment); §1.26.6
// Methods
public void addNotify(); §1.26.7
public int getAlignment(); §1.26.8
public String getText(); §1.26.9
protected String paramString(); §1.26.10
public void setAlignment(int alignment); §1.26.11
public void setText(String label); §1.26.12
}
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:
produces the following:
CENTER
public final static int CENTER
- Indicates that the label should be centered.
LEFT
public final static int LEFT
- Indicates that the label should be left justified.
RIGHT
public final static int RIGHT
- Indicates that the label should be right justified.
Label
public Label()
- Constructs an empty label with whose text is left justified.
Label
public Label(String label)
- Constructs a new label with the specified string of text left justified.
- Parameters:
label
-
the text that makes up the label
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.
- Parameters:
label
-
the string that makes up the label
alignment
-
the alignment value
addNotify
public void addNotify()
- This method calls the createLabel method (II-§1.41.12) of this object's toolkit (II-§1.10.20) in order to create a LabelPeer (II-§3.11) 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 (II-§1.10.2).
getAlignment
public int getAlignment()
- Returns:
- the current alignment of this label.
- See Also:
- setAlignment (II-§1.26.11).
getText
public String getText()
- Returns:
- the text of this label.
- See Also:
- setText (II-§1.26.12).
paramString
protected String paramString()
- Returns the parameter string representing the state of this label. This string
is useful for debugging.
- Returns:
- the parameter string of this label.
- Overrides:
- paramString in class Component (II-§1.10.51).
setAlignment
public void setAlignment(int alignment)
- Sets the alignment for this label to the specified alignment.
- Parameters:
alignment
-
the alignment value
- Throws
- IllegalArgumentException (I-§1.32)
- If an improper alignment was given.
- See Also:
- getAlignment (II-§1.26.8).
setText
public void setText(String label)
- Sets the text for this label to the specified text.
- Parameters:
label
-
the text that makes up the label
- See Also:
- getText (II-§1.26.9).
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.
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com