Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
wrap text inside a pushbutton

Subject: wrap text inside a pushbutton

From: Naresh Pai

Date: 29 Dec, 2009 23:42:04

Message: 1 of 7

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.

Subject: wrap text inside a pushbutton

From: Steven Lord

Date: 4 Jan, 2010 15:01:04

Message: 2 of 7


"Naresh Pai" <npai@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
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: wrap text inside a pushbutton

From: Naresh Pai

Date: 4 Jan, 2010 17:55:08

Message: 3 of 7

"Steven Lord" <slord@mathworks.com> wrote in message <hhsvrb$8fq$1@fred.mathworks.com>...
>
> "Naresh Pai" <npai@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
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

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

Subject: wrap text inside a pushbutton

From: Matt Fig

Date: 4 Jan, 2010 18:35:06

Message: 4 of 7

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!

Subject: wrap text inside a pushbutton

From: Doug Schwarz

Date: 4 Jan, 2010 19:05:00

Message: 5 of 7

Matt Fig wrote:
> 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!

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.

Subject: wrap text inside a pushbutton

From: Naresh Pai

Date: 4 Jan, 2010 19:42:05

Message: 6 of 7

Doug Schwarz <see@sig.for.address.edu> wrote in message <wZq0n.14168$DY5.8113@newsfe08.iad>...
> Matt Fig wrote:
> > 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!
>
> 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.

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

Subject: wrap text inside a pushbutton

From: Yair Altman

Date: 5 Jan, 2010 08:41:05

Message: 7 of 7

"Matt Fig" <spamanon@yahoo.com> wrote in message <hhtccq$7o1$1@fred.mathworks.com>...
> 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!

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us