Prev Up Next
Go backward to SubCanvas Components
Go up to Interface Components
Go forward to Sliders

Label Components


new Label()
new Label( some-string )
new Label( some-string, alignment-information )

While the "drawString" method can be used to place text in an applet's display, it is difficult to use "drawString" to place labels on components because one does not have precise control over component placement.

"Label" components provide an alternative way to add text to an applet's display. Basically, a "Label" is just a piece of text whose positioning on the screen is controlled by the layout manager like all other components. While this means that your control over its positioning will be somewhat imprecise, it at least ensures that the label will not overlap any other component.

The Label constructor method can be used with no parameters. In this case, the "setText" method described below can be used later to determine the text displayed. Normally, however, the Label constructor is used with at least one parameter, the text to be displayed.

An optional second parameter to the Label constructor can be used to control how the text displayed is aligned within the region allocated to the label by the layout manager. The value used for this parameter must be either "Label.CENTER", "Label.LEFT", or "Label.RIGHT" with the obvious interpretations.

There are no event handling methods associated with labels.

Other Label Methods


somelabel.setText( some-string );

As mentioned above, there is a "setText" method associated with every Label. This method can be used to change the text displayed by the label. It expects a single string that specifies the new text to display as a parameter.


Prev Up Next