Code covered by the BSD License  

Highlights from
uibutton: GUI pushbuttons with better labels

5.0

5.0 | 10 ratings Rate this file 51 Downloads (last 30 days) File Size: 3.13 KB File ID: #10743

uibutton: GUI pushbuttons with better labels

by

 

13 Apr 2006 (Updated )

Creates pushbutton uicontrol labeled with TeX or LaTeX strings.

| Watch this File

File Information
Description

Have you ever wanted to create a pushbutton uicontrol containing a Greek letter, some other mathematical expression or even just a multi-line label? This function will do it for you. It is very easy to use as it accepts all the same arguments as uicontrol with the addition of the Interpreter property which you can set to 'tex' or 'latex' and the Rotation property to set the angle of rotation of the text. Also, you can pass in a cell array of strings for the String property to get a multi-line label. For example,

  uibutton('String','Set \beta','Interpreter','tex')

Can also create something that looks like a text uicontrol.

Acknowledgements

This file inspired Euler Angle, Dcm, Quaternion, And Euler Vector Conversion/Teaching Gui, 3 D Puma Robot Demo, Dynamical System Viewer, and Curve Plotter3 D.Zip.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
12 Jun 2014 Nam  
09 Jul 2013 Mineralter  
26 Jul 2012 Gregory Vernon

Bravo. Does what it says it will do. There is a warning I receive in 2011b however:

Warning: The specified rectangle is not fully
contained within the figure. This will become an
error in a future release of MATLAB.
> In getframe at 68
In uibutton at 164

05 Nov 2010 Douglas Schwarz

Oliver, thanks for the comments. I was able to reproduce this behavior. I would argue that it's the result of a bug in getframe -- getframe ought to work since the figure is on screen, just not the main screen. Anyway, I have some ideas on how to work around it by temporarily moving the figure to the main screen and back again so watch for an update.

Doug

04 Nov 2010 Oliver

If the GUI which utilized the function is on a second display, the following error occurs:

?? Error using ==> capturescreen
The rectangle passed to getframe must be at least partially on screen

Error in ==> getframe at 105
x=builtin('capturescreen', varargin{:});

Error in ==> uibutton at 155
frame = getframe(ax);

Error in ==> hilDataRecorder>hilRecorderPreviewBtn_Callback at 125
uibutton(hObject,'string',{'Stop';'Preview'});

=========================================

In my case, I'm changing the string on a togglebutton object and would like the button to have two lines of text. So if the GUI is ever run on a second display, the function fails.

Great tool, nonetheless!

04 Nov 2010 Oliver  
28 Apr 2009 Emery  
15 Apr 2008 Matthew Adler

When I try to run this I get an error. I am able to generate the pushbutton with greek symbol, to size it and place it in the position I want with code:

alpha_button = uibutton('String','\alpha','Interpreter','tex','Position', [219 570 50 25]);

When I execute my GUI, however, the callback from my main pushbutton is not accessed. Also, if I move the symbol pushbutton into any position with 'position' I get the following error:

Error in ==> getframe at 35
x=capturescreen(varargin{:});

Error in ==> uibutton at 146
frame = getframe(ax);

Error in ==> lcgui>lcgui_OutputFcn at 78
alpha_rand = uibutton('String','\alpha','Interpreter','tex','Position', [219 570 50 25]);

Error in ==> gui_mainfcn at 248
[varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);

Error in ==> lcgui at 40
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

Error in ==> Lehigh_Corrosion_Fatigue at 10
set(lcgui,'HandleVisibility','on')

??? Error using ==> Lehigh_Corrosion_Fatigue
Error using ==> capturescreen
The rectangle passed to getframe must be at least partially on screen.

??? Error while evaluating uicontrol Callback

15 Apr 2008 Micke M

I would like to know where in the GUI-code to put the uibutton(...);

(For those of us that are quite new to GUIs)

30 Mar 2008 ding lu

very good

19 Feb 2008 Agnieszka Herman

Great! Works without any problems and it saved me really lots of time. Thank you!

19 Sep 2006 Trevor Fichera

Just what I needed. I am using it in Matlab Ver. 6.5.0 (R13.0.1). I had trouble with the isscalar(h) command, but I replaced it with ~any(size(h)-1) and it works great.
For multiline text buttons, try
uibutton(h,'String',' Print\newlineReport','HorizontalAlignment','center')
where h is the handle of an existing uicontrol button.

If anyone knows of a good LaTeX reference online, I would appreciate the post.

04 Jun 2006 ebrahim sepidbar

pushbotton

16 Apr 2006 Jiro Doke

Very nice. I like how you create an image and use that as an ICON for the buttons. This guarantees that it behaves exactly like uicontrols.

One comment: when the style is TEXT, it creates a text object. In the code, you comment that it doesn't return the handle because it is not a UICONTROL. You should probably say something about that in the help text. Also, if someone (by mistake) asks for the handles, as in h=uibutton('style', 'text', ...), it gives an error because hout is not assigned. Maybe there's a better response to this, such as returning an empty variable or displaying a message.

15 Apr 2006 Peter Nave  
Updates
17 Apr 2006

Added ability to pass in figure or uipanel handle as first argument. Changed documentation.

07 Mar 2010

Added ability to set the text rotation angle.

10 Mar 2010

Fixed bug introduced in previous update.

05 Nov 2010

Workaround for bug in getframe in case parent figure is on a second screen.

Contact us