label = XtVaCreateManagedWidget ("name",
xmLabelGadgetClass, parent,
resource−value−list,
NULL);
12.1.2 Text Labels
A Label widget or gadget can display either text or an image. The XmNlabelType resource controls the type of
label that is displayed; the resource can be set to XmSTRING or XmPIXMAP. The default value is XmSTRING, so if
you want to display text in a Label, you do not need to set this resource explicitly.
The resource that specifies the string that is displayed in a Label is XmNlabelString. The value for this resource
must be a Motif compound string; common C character strings are not allowed. The following code fragment shows
the appropriate way to specify the text for a Label:
Widget label;
XmString str = XmStringCreateLocalized ("A Label");
label = XtVaCreateManagedWidget ("label",
xmLabelWidgetClass, parent,
XmNlabelString, str,
NULL);
XmStringFree (str);
If the XmNlabelString resource is not specified, the Label automatically converts its name into a compound
string and uses that as its label. Therefore, the previous example could also be implemented as follows:
Widget label;
label = XtVaCreateManagedWidget ("A Label",
xmLabelWidgetClass, parent,
NULL);
This method of specifying the label string for the widget is much simpler than using a compound string. It avoids the
overhead of creating and destroying a compound string, which is expensive in terms of allocating and freeing
memory. The problem with the name of the widget shown above is that it is illegal as a widget ...