Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Label

Fields , Constructors , Methods , Footnotes

public  class  java.awt.Label
    extends  java.awt.Component  
{
        // Fields
    public final static int CENTER;	
    public final static int LEFT;	
    public final static int RIGHT;	

        // Constructors
    public Label();	
    public Label(String  label);	
    public Label(String  label, int  alignment);	

        // Methods
    public void addNotify();	
    public int getAlignment();	
    public String getText();	
    protected String paramString();	
    public void setAlignment(int  alignment);	
    public void setText(String  label);	
}

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:

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

produces the following:


Fields


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.


Constructors


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.

ParameterDescription
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.

ParameterDescription
label the string that makes up the label
alignment the alignment value


Methods


addNotify

public void addNotify() 

This method calls the createLabel method of this object's toolkit in order to create a LabelPeer 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 .


getAlignment

public int getAlignment() 

Return Value:

Returns the current alignment of this label.

See Also: setAlignment .


getText

public String getText() 

Return Value:

Returns the text of this label.

See Also: setText .


paramString

protected String paramString() 

Returns the parameter string representing the state of this label. This string is useful for debugging.

Return Value:

Returns the parameter string of this label.

Overrides:

paramString in class Component .


setAlignment

public void setAlignment(int  alignment) 

Sets the alignment for this label to the specified alignment.

ParameterDescription
alignment the alignment value

Throw:

IllegalArgumentException

If an improper alignment was given.

See Also: getAlignment .


setText

public void setText(String  label) 

Sets the text for this label to the specified text.

ParameterDescription
label the text that makes up the label

See Also: getText .


Footnotes

(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.

Top© 1996 Sun Microsystems, Inc. All rights reserved.