Parent document is top of "Motif FAQ (Part 5 of 9)"
Previous document is "154) Why doesn't label alignment work in a RowColumn?"
Next document is "156) How can I have a vertical label?"

155) How can I set a multiline label?

[Last modified: Mar 96]

Answer:  In .Xdefaults

      *XmLabel*labelString:              Here\nis\nthe\nLabel

This method does not seem to work in some of the older Motif 1.0 versions.

In code,

      char buf[128];
      XmString msg;
      sprintf(buf, "Here\nis\nthe\nLabel");
      msg = XmStringCreateLtoR(buf, XmSTRING_DEFAULT_CHARSET);
      XtSetArg (args[n], XmNlabelString, msg);

Gives a four line label, using the escape sequence \n for a newline.  Here's
another approach from Jean-Philippe Martin-Flatin <syj@ecmwf.int>

#include <Xm/Xm.h>
#include <string.h>

/*-----------------------------------------------------
    Create a new XmString from a char*

    This function can deal with embedded 'newline' and
    is equivalent to XmStringCreateLtoR,
    except it does not use non AES compliant charset
    XmSTRING_DEFAULT_CHARSET
----------------------------------------------------*/
XmString xec_NewString(char *s)
{
    XmString xms1;
    XmString xms2;
    XmString line;
    XmString separator;
    char     *p;
    char     *t = XtNewString(s);   /* Make a copy for strtok not to */
                                    /* damage the original string    */


    separator = XmStringSeparatorCreate();
    p         = strtok(t,"\n");
    xms1      = XmStringCreateLocalized(p);

    while (p = strtok(NULL,"\n"))
    {
        line = XmStringCreateLocalized(p);
        xms2 = XmStringConcat(xms1,separator);
        XmStringFree(xms1);
        xms1 = XmStringConcat(xms2,line);
        XmStringFree(xms2);
        XmStringFree(line);
    }

    XmStringFree(separator);
    XtFree(t);
    return xms1;
}


Do not use XmStringCreateLocalized() - it does not process the newline
character in the way you want.   In Motif 1.x, XmStringCreateLocalized() does
NOT process newlines, but XmStringCreateLtoR() does.

Thanks to Paul Tomblin (ptomblin@xcski.com) for the newline clarification.

Parent document is top of "Motif FAQ (Part 5 of 9)"
Previous document is "154) Why doesn't label alignment work in a RowColumn?"
Next document is "156) How can I have a vertical label?"