This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

textwrap

Wrap text for uicontrol

Syntax

outtext = textwrap(h,text)
outtext = textwrap(h,text,columns)
outtext = textwrap(text,columns)
[outtext,position] = textwrap(...)

Description

outtext = textwrap(h,text) returns a wrapped cell array of character vectors that fits inside the UIControl specified by h. The text argument is a cell array of character vectors or a string array. Each element in the array contains a single line of text. outtext is the wrapped cell array of character vectors. Each cell of text is considered a paragraph.

outtext = textwrap(h,text,columns) returns outtext with each line wrapped at the number of columns specified by the columns argument. Spaces are included in the character count.

outtext = textwrap(text,columns) returns a wrapped cell array of character vectors for a specific text and number of columns.

[outtext,position] = textwrap(...) returns the recommended position of the UIControl in the units of the UIControl. The position output argument considers the extent of the multiline text in the x and y directions.

textwrap maintains the original line breaks in the input array and adds new ones. It can calculate UIControl positions with any type of Units, including normalized units.

Examples

Place wrapped text in two UIControl text boxes. The position of the left text box is calculated by textwrap in pixel units. The position of the right text box is calculated in character units.

figure('Position',[560 528 350 250]);
% Make a text uicontrol to wrap in Units of Pixels
% Create it in Units of Pixels, 100 wide, 10 high
pos = [10 100 100 10];   
ht = uicontrol('Style','Text','Position',pos);
txt = {'This is the left text box.',...
          'This text is wrapped in pixel units',...
          'with a position determined by TEXTWRAP.'};
% Wrap text, also returning a new position for ht
[outtext,newpos] = textwrap(ht,txt);

set(ht,'String',outtext,'Position',newpos)

% Make another text uicontrol to wrap to a column width of 20
colwidth = 20;
% Create it in Units of Pixels, 100 wide, 10 high
pos1 = [150 100 100 10]; 
ht1 = uicontrol('Style','Text','Position',pos1);
txt1 = {'This is the right text box.',...
          'This text wrapped in character units',...
          'using a column width of 20.'};
outtext1 = textwrap(ht1,txt1,colwidth);
% Reset Units of ht1 to Characters to use the result
set(ht1,'Units','characters')
newpos1 = get(ht1,'Position')

% Set new Position in Characters to be specified colwidth
% with height the length of the outtext1 cell array + 1.
newpos1(3) = colwidth; 
newpos1(4) = length(outtext1)+1

set(ht1,'String',outtext1,'Position',newpos1)

See Also

|

Introduced before R2006a