Java Reference
In-Depth Information
Figure 13.7
A sample output of the JRadioButtonDemo program.
Labels
A label is a string or icon that is displayed within a container. Labels generate
the events that all components generate, like focus and mouse events, but they
do not generate any other events such as action or item events. In most cases,
you will not be interested in the events that a label generates because the pur-
pose of the label is to simply display the text or icon.
The java.awt.Label class represents an AWT label and has three constructors:
public Label(). Constructs an empty label.
public Label(String text). Constructs a label with the given text.
public Label(String text, int alignment). Creates a label with the speci-
fied alignment; possible alignment values are Label.RIGHT, Label.LEFT,
and Label.CENTER.
An AWT label can only represent text, while a Swing label can represent
either text or an icon.
For example, the following statement creates a Label that will be centered in
the region that it is laid out in by the layout manager:
Label hi = new Label(“Hello”, Label.CENTER);
The ListDemo program in the upcoming Lists section demonstrates using an
AWT label.
The javax.swing.JLabel class represents a Swing label and has six construc-
tors that take in a variation of the following parameters:
String text.
Represents the text of the label.
Search WWH ::




Custom Search