Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

wrap text inside a pushbutton

231 views
Skip to first unread message

Naresh Pai

unread,
Dec 29, 2009, 6:42:04 PM12/29/09
to
Is there a way to set uicontrol properties such that the text inside a pushbutton will wrap itself?

The alternative would be to use static text on the pushbutton.

Steven Lord

unread,
Jan 4, 2010, 10:01:04 AM1/4/10
to

"Naresh Pai" <np...@uark.edu> wrote in message
news:hhe44c$q55$1...@fred.mathworks.com...

> Is there a way to set uicontrol properties such that the text inside a
> pushbutton will wrap itself?
> The alternative would be to use static text on the pushbutton.

No, but in the callback where you set the String property of the button you
can use TEXTWRAP:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textwrap.html

--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


Naresh Pai

unread,
Jan 4, 2010, 12:55:08 PM1/4/10
to
"Steven Lord" <sl...@mathworks.com> wrote in message <hhsvrb$8fq$1...@fred.mathworks.com>...

I tried using textwrap as follows:

% Intialize a figure
hf = figure('Name','GUI');

% Define a uicontrol button
Btn_temp = uicontrol(...
'Parent',hf,...
'Units','normalized',...
'Position',[0.7,.15,.2,.1],...
'Style','pushbutton');

% Define a string for button
string = {'ABC DEF',...
'GHI JKL'};

% wrap string for uicontrol button
[outstring,newpos] = textwrap(Btn_temp,string);

% apply the string to the uicontrol button
set(Btn_temp,'String',outstring,'Position',newpos);

%The button string does not get the second line i.e. GHI JKL

Matt Fig

unread,
Jan 4, 2010, 1:35:06 PM1/4/10
to
From the documentation:

"For uicontrol objects that display only one line
of text (check box, push button, radio button, toggle button),
if the string value is specified as a cell array of strings or padded string
matrix, only the first string of a cell array or of a padded string matrix
is displayed; the rest are ignored. Vertical slash ('|') characters are not
interpreted as line breaks and instead show up in the text displayed in the
uicontrol."

You might be able to do something with the underlying JAVA. Putting a textbox over the top of the pushbutton introduces problems as well, because clicking on the string will not trigger the pushbutton's callback.

We will bring the JAVA man to this thread:

Calling Yair Altman!

Doug Schwarz

unread,
Jan 4, 2010, 2:05:00 PM1/4/10
to

Indeed, I would be interested in a Java way to do this, but in the
meantime my uibutton is available:

<http://www.mathworks.com/matlabcentral/fileexchange/10743-uibutton-gui-pushbuttons-with-better-labels>

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Naresh Pai

unread,
Jan 4, 2010, 2:42:05 PM1/4/10
to
Doug Schwarz <s...@sig.for.address.edu> wrote in message <wZq0n.14168$DY5....@newsfe08.iad>...

Thanks Doug! That works perfect for now. Here is the updated code (after downloading uibutton), if someone is interested:

% Intialize a figure
hf = figure('Name','GUI');

% Define a string for button


string = {'ABC DEF',...
'GHI JKL'};

% Define a uicontrol button
Btn_temp = uibutton(...


'Parent',hf,...
'Units','normalized',...
'Position',[0.7,.15,.2,.1],...

'Style','pushbutton',...
'String',string);

--Naresh

Yair Altman

unread,
Jan 5, 2010, 3:41:05 AM1/5/10
to
"Matt Fig" <spam...@yahoo.com> wrote in message <hhtccq$7o1$1...@fred.mathworks.com>...

Simply use HTML formatting:
set(Btn_temp, 'String', '<html>ABC DEF<br>GHI JKL');

More information:
http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/

Yair Altman
http://UndocumentedMatlab.com

Anvt

unread,
Jan 22, 2016, 10:40:12 AM1/22/16
to
"Yair Altman" <altma...@gmailDEL.comDEL> wrote in message <hhutv1$h8g$1...@fred.mathworks.com>...
Thank you!
Helped me, works in GUIDE also.

Great fan of your work Sir! Thanks again
0 new messages