MATLAB Answers

GUI position property issue...

51 views (last 30 days)
Chris E.
Chris E. on 11 Jul 2014
Commented: Joseph Cheng on 11 Jul 2014
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
  5 Comments
Chris E.
Chris E. on 11 Jul 2014
Hello Sara and Joseph,
Well I know that position parameter properties goes like this: [xposition yposition width height], but I was hoping for was a way to look at part of a gui that is located at the top of the gui. Well the code you gave:
pos = get(gcf,'position');
set(gcf,'position', [pos(1:3) pos(4)/2])
is what I already have and know.
Essentially I need:
% Make figure 1
f1 = figure('Name','Window 1');
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Upper Data', ...
'Callback','feval(plotf)', ...
'position', [250 180 100 15]);
%NOTE I physically changed the position of the txt to match what I want, in the real situation I can not change the position of the txt
set(gcf,'position', [677 610 560 210])
%Also the "upper data" is in the area of [677 610 560 420] not [677 610 560 210] (changed it so you know what it needs to look like), I have to find a way to display data that is in the upper portion of the GUI but not the lower portion of a GUI.
But I can not move the positions of the txt boxes, I need to move the position of the GUI, The more I'm thinking about it the more i think it is not possible in this setup for position in GUI's.
My task was to change the GUI without changing the positions of the information inside it.
I hope that maybe clarifies what I need.
Thank you though! I very much appreciate any help anyone is willing to offer!!!

Sign in to comment.

Accepted Answer

Joseph Cheng
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
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!