GUI position property issue...
11 views (last 30 days)
Show older comments
Hello all! Well I'm attempting to change the position property of a GUI. I need to display different parts of a GUI at different times. So I have an example here showing two text boxes that show upper data and lower data, I need to resize the GUI to fit the lower data then fit the upper data. I know I can get the lower half easy, but the upper half is being a pain. Here is the example code:
% Make figure 1
f1 = figure('Name','Window 1');
%Add some text boxes
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Upper Data', ...
'Callback','feval(plotf)', ...
'position', [250 380 100 15]);
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Lower Data', ...
'Callback','feval(plotf)', ...
'position', [250 20 100 15]);
%grab current position data
get(gcf,'position')
%so you see both the upper and lower regions
pause(2)
%set new data
set(gcf,'position', [677 610 560 210])
What I need is to find a way to get essentially a position of:
set(gcf,'position', [677 610 560 210:420])
But that code is not the correct way to accomplish this. I need is a way to display the upper regions just like I display the lower regions.
Please help!
Thanks
Accepted Answer
Joseph Cheng
on 11 Jul 2014
as the position parameter starts with what i remember as the lower left corner you cannot just resize the figure to show the top portion. since if you resize it the bottom corner is locked to the bottom corner of the window. What you can do is shift the everything else!
% Make figure 1
f1 = figure('Name','Window 1');
%grab/set current position data
fposition = get(gcf,'position')
yoffset = [0 fposition(4)/2 0 0];
u1pos = [250 20 100 15];
u2pos = [250 380 100 15];
%Add some text boxes
u2 = uicontrol(f1, ...
'Style','text', ...
'String','Upper Data', ...
'Callback','feval(plotf)', ...
'position', u2pos);
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Lower Data', ...
'Callback','feval(plotf)', ...
'position', u1pos);
%so you see both the upper and lower regions
pause(2)
%set new data
% set(gcf,'position', [677 610 560 210])
set(gcf,'position',[fposition(1:3) fposition(4)/2])
% What I need is to find a way to get essentially a position of:
pause(2)
set(u1,'position',u1pos-yoffset);
set(u2,'position',u2pos-yoffset);
4 Comments
Joseph Cheng
on 11 Jul 2014
so i'd recommend create a function that takes inputs of handles,x, y and top/bottom/left/right so all you need to do then do what i did above for all the items. so you only have to write this up once.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!