Java AWT

Previous Chapter 19
java.awt Reference
Next
 

Label

Name

Label

[Graphic: Figure from the text]

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 text label 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, or RIGHT.

Throws

IllegalArgumentException

If alignment is not one of CENTER, LEFT, or RIGHT.

Description

Constructs a Label object, with a given alignment and text of label.

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, or RIGHT.

Throws

IllegalArgumentException

If alignment is not one of CENTER, LEFT, or RIGHT.

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


Previous Home Next
ItemSelectable (New) Book Index LayoutManager

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java