Labels

Having covered the features of the Component class, we can now look at some of the simplest components. The first component introduced here is a Label. A label is a Component that displays a single line of static text.[3] It is useful for putting a title or message next to another component. The text can be centered or justified to the left or right. Labels react to all events they receive. However, they do not get any events from their peers.

[3] Java tutorial (from Anonymous) includes a multiline Label component.

Label Methods

Constants

There are three alignment specifiers for labels. The alignment tells the Label where to position its text within the space allotted. Setting an alignment for a Label might not do anything noticeable if the LayoutManager being used does not resize the Label to give it more space. With FlowLayout, the alignment is barely noticeable. See Layouts, for more information.

Constructors Text Alignment

Figure 5.2: Labels with different alignments

[Graphic: Figure 5-2]Miscellaneous methods

java.awt.Label[0,0,0x0,invalid,align=right,label=ZapfDingbats] 

Label Events

The Label component can react to any event it receives, though the Label peer normally does not send any. However, there is nothing to stop you from posting an event yourself.