MATLAB: Is it possible to use multiple lines of text in the ‘String’ Property of a uicontrol

MATLABmulti-linemultilinestring

Is it possible to use multiple lines of text in the 'String' Property of a uicontrol? How can I force my text string to wrap to the next line in a static text uicontrol when it is too long to fit on one line?

Best Answer

In MATLAB 6.1 (R12.1), it is possible to define multiline strings for the following uicontrols:
STYLE
-----
edit
text
popupmenu
listbox
For multiple items on a pop-up menu or a list box, items can be specified as a cell array of strings, a padded string matrix, or within a string vector separated by vertical slash ('|') characters.
For multiple line editable text or static text controls, line breaks occur between each row of the string matrix, each cell of a cell array of strings, and after any \n characters embedded in the string. Vertical slash ('|') characters are not interpreted as linebreaks, and instead show up in the text displayed in the uicontrol.
For the remaining uicontrol styles, which display only one line of text, only the first string of a cell array of strings or of a padded string matrix is displayed; all the rest are ignored. Vertical slash ('|') characters are not interpreted as linebreaks and instead show up in the text displayed in the Uicontrol.
Below is an example of how to force a text string to wrap to the next line:
A = cell(1,2);
A{1,1} = 'hello';
A{1,2} = 'there';
mls = sprintf('%s\n%s',A{1,1},A{1,2});
h= uicontrol('Style','Edit','String',mls,'Position',[10 200 75 100],'Max',2);
h= uicontrol('Style','Text','String',mls,'Position',[10 80 75 100],'Max',2)