Java AWT Label Class Methods
There are a few predefined Methods associated with Java AWT Label as mentioned below:
Sr. No. |
Method | Description |
---|---|---|
1. |
void setText(String text) |
Sets the text of the label. |
2. |
String getText() |
Gets the text of the label. |
3. |
void setAlignment(int alignment) |
Sets the alignment of the text in the label. Possible values: Label.LEFT , Label.RIGHT , Label.CENTER . |
4. |
int getAlignment() |
Gets the alignment of the text in the label. |
5. |
void addNotify() |
Creates the peer for the label. |
6. |
AccessibleContext getAccessibleContext() |
Gets the AccessibleContext associated with the label. |
7. |
void addNotify() |
Creates the peer (native window) for the label. |
Java AWT Label
Abstract Window Toolkit (AWT) was Java’s first GUI framework, and it has been part of Java since version 1.0. It contains numerous classes and methods that allow you to create windows and simple controls. Controls are components that allow a user to interact with your application in various ways.
The AWT supports the following types of controls:
- Labels
- Push buttons
- Checkboxes
- Choice lists
- Lists
- Scroll bars
- Text Editing
The easiest control to use is a label. A Label is an object of type Label (class in java.awt.Component), and it contains a string, which it displays within a container. Labels are passive controls that do not support any interaction with the user. To create a label, we need to create the object of the Label class.