Fanning Software Consulting

Multiple Line IDL Label Widgets

QUESTION: Is it really (I mean really REAL, VERIFIABLE, UNDENIABLE etc.) true that one cannot accomodate more than one line of text on a WIDGET_LABEL? Curiously, I never had the need to put multiple lines of text on a label before now. But, I did today, and I was surprized to learn that it is apparently not possible (i.e., new line characters don't work). Do you have any ideas?

ANSWER: Before today I would have told you it was really, verifiably, undeniably true that widget labels could only have a single line of text. But I would have been lying to you. Thanks to biophys, we now know the truth.

The secret is to insert your carriage return characters into the string, not by embedding the !C character as you would with a multi-line title on a line plot, but by using the actual carriage control character, which has an ASCII value of 13. You also have to make sure your label is large enough to accommodate a multi-line character string. Code something like this will work.

   tlb = Widget_Base()
   labelText = 'This is the first line of text' + String(13B) + 'And this is the second'
   label = Widget_Label(tlb, VALUE=labelText, YSIZE=40, UNITS=0)
   Widget_Control, tlb, /Realize 

Version of IDL used to prepare this article: IDL 7.0.3.

Web Coyote's Guide to IDL Programming