Making GUI with sub-elements resizable in a quick way
显示 更早的评论
When developing a GUI in guide, there is a global GUIDE option that let's you make the GUI resizable in a way that all sub-elements resize proprtionately with the figure.
However, I am given a programmatically generated GUI and I would like to modify the mfile so that it is resizable in the same way. Is there a quick way to do this, i.e., by modifying a single property of the parent figure, or do I have to write a ResizeFcn callback that manually alters the size/position of the sub-elements one by one?
采纳的回答
更多回答(2 个)
per isakson
2014-6-6
编辑:per isakson
2014-6-6
Based on a simple experiment with R2013a, I think this will do the trick
h = findobj( fh, '-property', 'Units' );
set( h, 'Units', 'Normalized' )
where fh is the handle of the GUI (figure).
I'm not sure about pro/cons regarding setting the unit property of the figure itself. I guess it doesn't hurt.
BTW, you might need to replace findobj by findall
1 个评论
chlor thanks
2016-8-3
Hi per, I want to try your code to resize the static text in my text box made in GUIDE, is this possible? Is so, should I put handles.statictext instead of fh in the code and where shall I insert this code? Thanks!
Image Analyst
2014-6-6
You can programmatically resize your GUI like this:
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
You can also use position instead of outerposition and the array is [left, top, width, height] and has values ranging from 0 to 1 (which is the fraction of the total screen size), so pick whatever values you want.
2 个评论
Matt J
2014-6-6
Image Analyst
2014-6-11
No it does not, but that doesn't matter. The figure will scale, but if the units of the other controls are all "characters" then they won't scale and will appear in the upper left corner. If you want them to scale/resize also, then set the units of all the controls to normalized. It looks like per's code should do that.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!