GUI position property issue...

7 ビュー (過去 30 日間)
Chris E.
Chris E. 2014 年 7 月 11 日
コメント済み: Joseph Cheng 2014 年 7 月 11 日
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 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 7 月 11 日
yes Sara is absolutely correct. the position parameter properties is [xposition yposition width height].
Chris E.
Chris E. 2014 年 7 月 11 日
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!!!

サインインしてコメントする。

採用された回答

Joseph Cheng
Joseph Cheng 2014 年 7 月 11 日
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 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 7 月 11 日
well... without digging up for more info you can set the position for multiple items... so group them like i did here i know i grouped both the top and bottom but see what i was trying to do. group all your top stuff with under a variable TOP or here i did U. so setting the handles inside U, to the cell representation of the position it'll offset everything inside U by that amount. probably a cleaner way to show the new position matrix. if you're not familiar with mat2cell look at the documentation and i'm using the rowDist parameter where i'm saying break up the matrix into one row per cell.
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);
pause(3)
U = [u1 u2];
Upos = [u1pos;u2pos];
%shift all by xoffset
xoffset = 20;
set(U,{'position'},mat2cell(Upos+[xoffset*ones(length(U),1) zeros(length(U),3)],ones(length(U),1)))
Joseph Cheng
Joseph Cheng 2014 年 7 月 11 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by