GUI position property issue...
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chris E.
il 11 Lug 2014
Commentato: Joseph Cheng
il 11 Lug 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 Commenti
Joseph Cheng
il 11 Lug 2014
yes Sara is absolutely correct. the position parameter properties is [xposition yposition width height].
Risposta accettata
Joseph Cheng
il 11 Lug 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 Commenti
Joseph Cheng
il 11 Lug 2014
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
il 11 Lug 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!