- Undocumented Matlab - https://undocumentedmatlab.com/blog_old -
GUIDE customization
Posted By Yair Altman On June 10, 2009 | 6 Comments
GUIDE is the acronym for Matlab’s Graphical User Interface Design Editor. It is very handy for designing simple GUI figures, although my experience has shown that it has limitations for complex GUIs. Nevertheless, GUIDE is the tool used by most Matlab developers when designing GUIs. In this post, I will show a few undocumented customizations that could help make GUIDE sessions more productive.
The starting point is GUIDE’s undocumented return value, which is a Java reference to the Layout Editor panel within the GUIDE figure frame:
>> h = guide h = Layout Document [untitled] >> h.getClass ans = class com.mathworks.toolbox.matlab.guide.LayoutEditor
This return handle can be used to access GUIDE components and functionality. We can start by inspecting the interesting GUIDE layout hierarchy using my FindJObj utility [3], and the associated properties and method using my UIInspect utility [4]:
>> h.findjobj;
>> h.uiinspect;
Note: If you wish to see the hierarchy of the entire GUIDE figure frame, simply run FindJObj on the frame reference, by either of the two following methods (and similarly for UIInspect):
>> findjobj(h.getFrame);
>> findjobj(h.getTopLevelWindow);
We see that the Layout Editor contains, in addition to the expected LayoutArea and two MWScrollbars, several objects that relate to a ruler. These rulers can be activated via the GUIDE menu (Tools / Grid and Rulers), or via the Matlab Command Prompt as described below:
Looking at the ruler properties in FindJObj or UIInspect, we can see a settable boolean property called “RulerState”. If we turn it on we can see that a very handy pixels-ruler appears. Once we set this property, it remains in effect for every future GUIDE session:
h.getComponent(0).getComponent(4).setRulerState(true); % Horizontal h.getComponent(0).getComponent(5).setRulerState(true); % Vertical
Note: RulerState actually controls a system preference (LayoutShowRulers, a boolean flag) that controls the visibility of both rulers, and persists across Matlab/GUIDE sessions. To change the visibility of only a single ruler for this GUIDE session only, or on old Matlab versions (e.g. Matlab 7.1 aka R14 SP3) that do not have the ‘RulerState’ property, use the hide()/show()/setVisible(flag) methods, or set the ‘Visible’ property:
% Equivalent ways to show horizontal ruler for this GUIDE session only hRuler = h.getComponent(0).getComponent(4); % =top horizontal ruler set(hRuler, 'Visible','on'); hRuler.setVisible(true); % or: hRuler.setVisible(1) hRuler.show();
Using this method, we can customize the rulers – options which are unavailable using the standard GUIDE menu options: We can specify horizontal/vertical grid size, tick & label interval and similar ruler properties. For example, let’s set a 5-pixel minor tick interval, 25-pixel major interval, labels every 50 pixels, starting offset of 40 pixels and a ruler size limited at 260 pixels:
hRuler = h.getComponent(0).getComponent(4); % =top horizontal ruler set(hRuler, 'MinorInterval',5, 'MajorInterval',25); set(hRuler, 'LabelInterval',50, 'LabelUnit',50); set(hRuler, 'Margin',40, 'Length',260);
Note that the vertical ruler’s labels start (=LabelStart property) at the figure’s height, and have a decreasing LabelInterval of -50. This is done because Java coordinates start counting from the top-left corner downward, whereas Matlab counts from the bottom-left upward. In GUIDE, we naturally wish to display the Matlab coordinates, hence the transformation.
Note: unfortunately, most of these properties do not have equivalent settable system properties that I could find. Here is a list of all the GUIDE-related system properties that I found:
Have you discovered other undocumented features in GUIDE? If so, please share your findings in the comments section below.
Warning: These undocumented features are way deep in unsupported territory. They depend heavily on Matlab’s internal implementation, which may change without any prior notice between Matlab releases. They work ok on Matlab versions 7.1 (R14 SP3) through 7.6 (R2008a), and perhaps on other versions as well. However, the very next Matlab release might break these features, so beware.
Categories: GUI, Hidden property, High risk of breaking in future versions, Java, Stock Matlab function
Article printed from Undocumented Matlab: https://undocumentedmatlab.com/blog_old
URL to article: https://undocumentedmatlab.com/blog_old/guide-customization
URLs in this post:
[1] Image: https://undocumentedmatlab.com/feed/
[2] email feed: https://undocumentedmatlab.com/subscribe_email.html
[3] FindJObj utility: http://www.mathworks.com/matlabcentral/fileexchange/14317
[4] UIInspect utility: http://www.mathworks.com/matlabcentral/fileexchange/17935
[5] Detecting window focus events : https://undocumentedmatlab.com/blog_old/detecting-window-focus-events
[6] Uitable sorting : https://undocumentedmatlab.com/blog_old/uitable-sorting
[7] Customizing Matlab labels : https://undocumentedmatlab.com/blog_old/customizing-matlab-labels
[8] FindJObj – find a Matlab component’s underlying Java object : https://undocumentedmatlab.com/blog_old/findjobj-find-underlying-java-object
[9] JIDE Property Grids : https://undocumentedmatlab.com/blog_old/jide-property-grids
[10] Customizing Matlab uipanels : https://undocumentedmatlab.com/blog_old/customizing-matlab-uipanels
[11] : https://undocumentedmatlab.com/blog/getting-default-hg-property-values
Click here to print.
Copyright © Yair Altman - Undocumented Matlab. All rights reserved.
6 Comments To "GUIDE customization"
#1 Pingback By Matlab layout managers: uicontainer and relatives | Undocumented Matlab On June 9, 2010 @ 3:03 pm
[…] When designing Matlab applications, we can either use Matlab’s designer (guide), or manually position each GUI component programmatically, using its Position property. […]
#2 Comment By jeff On November 10, 2011 @ 7:10 pm
So why does MatLab have so many features that are undocumented? Seems like some of their undocumented features would actually be useful to the users.
#3 Comment By Yair Altman On November 12, 2011 @ 8:39 am
@Jeff – This is a great question, so I decided to expand on it in an upcoming blog article. Stay tuned!
#4 Comment By jeff On November 12, 2011 @ 4:56 pm
Will do. Thanks for all of your solutions. It’s a big help.
#5 Comment By Rob On January 4, 2016 @ 1:04 pm
Can this technique be used to change the default units of objects generated in GUIDE to ‘pixels’ or ‘normalized’ (or something else less infuriating than ‘characters’…)?
#6 Comment By Yair Altman On January 4, 2016 @ 3:21 pm
@Rob – I believe that this might help you: [11]