Label objects are used to present labels and other permanent text on displays.

The following function creates a new Label, so you need to save it in a variable (so you can use it later).

Function Description
Label(text, alignment, foregroundColor, backgroundColor) Create a new label with specified text (string), alignment (LEFT, CENTER or RIGHT – default is LEFT), foregroundColor is the color of the text (default is Color.BLACK), and backgroundColor is the label’s background color (default is transparent).

For example, a label may be created as follows:

Once a label has been created, it cannot be resized.  So, you should create it with the widest (possibly blank) string necessary, e.g.,

Once a label has been created, it may be added to a Display specifying where to place its top-left corner.

Also, the following functions are available:

Function Description
label1.setText(text) Updates the contents of label1 to text (a string).
label1.getText() Returns the text contained in label1 (as a string).
label1.setBackgroundColor(color) Change the background color of label1 (e.g., Color.WHITE).  If no color provided, use dialog box to select.
label1.getBackgroundColor() Returns the current background color of label1.
label1.setForegroundColor(color) Change the foreground (text) color of label1 (e.g., Color.BLACK). If no color provided, use dialog box to select.
label1.getForegroundColor() Returns the current foreground (text) color of label1.
label1.setFont(font) Changes the font used in label1, where font is e.g., Font(“Dialog”, Font.PLAIN, 12), or Font(“Serif”, Font.ITALIC, 16).
label1.getFont() Returns the current font used in label1.


The GUI library uses Java fonts.  Fonts can be set as follows:

The default font used by Label is Font(“Dialog”, Font.PLAIN, 12).

The following five font families are available:

  • Dialog
  • DialogInput
  • Monospaced
  • Serif
  • SansSerif

A Serif font is similar to Times New Roman. A Sans Serif font is similar to Arial.  A Monospaced font is similar to Courier.

Fonts also have style and size.

Styles are Font.PLAIN, Font.BOLD and Font.ITALIC.

Sizes are integers, e.g., 19, 12, and 24.