Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

textwrap

Wrap text for uicontrol

Syntax

outstring = textwrap(h,instring)
outstring = textwrap(h,instring,columns)
[outstring,position] = textwrap(...)

Description

outstring = textwrap(h,instring) returns a wrapped cell array of character vectors, outstring, that fits inside the uicontrol h. instring is a cell array containing of character vectors, with each cell containing a single line of text. outstring is the wrapped cell array of character vectors. Each cell of the input character vectors is considered a paragraph.

outstring = textwrap(h,instring,columns) returns an outstring with each line wrapped at columns characters. Spaces are included in the character count.

[outstring,position] = textwrap(...) returns the recommended position of the uicontrol in the units of the uicontrol. position considers the extent of the multiline text in the x and y directions.

textwrap maintains the original line breaks in the input cell 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
[outstring,newpos] = textwrap(ht,txt);

set(ht,'String',outstring,'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.'};
outstring1 = 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 outstring1 cell array + 1.
newpos1(3) = colwidth; 
newpos1(4) = length(outstring1)+1

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

More About

collapse all

Tips

Do not call copyobj or textwrap (which calls copyobj) inside a CreateFcn. Copying the uicontrol object fires the CreateFcn callback repeatedly, which raises a series of error messages.

See Also

|

Introduced before R2006a

Was this topic helpful?