Resize figure changes position and dimension of some objects

15 views (last 30 days)
I have some issues with positioning and the dimension for different kind of objects, for the following code. When you resize the figure, you can see that the button and listbox have always the same size and position to each other.
I would like to set the position and dimension of the panel and axes like that, too. I don´t want to get the objects resized, when the user is changing the figure size and I want to get a full screen at the beginning as well.
Is there any possibility to do that?
function GUI()
close all
data = createData();
gui = createInterface();
function data = createData()
data.Test_data = {'Test1','Test2','Test3', 'Test4'};
data.arrow_p1 = [0.5 1]; % Startpunkt x1,y1
data.arrow_p2 = [0 -1]; % Breite des Pfeils = 0 und Länge des Pfeils mit Richtung -1 (nach unten)
data.Dir_path = pwd;
assignin('base','data', data);
end
function gui = createInterface()
% Gui creation
gui.Window = figure('Units','normalized','OuterPosition',[0 0 0.9 0.9],...
'Name','Test', ...
'NumberTitle', 'off','MenuBar', 'none');
% Menübar
gui.FileMenu1 = uimenu( gui.Window, 'Label', 'Datei' );
gui.FIleMenu5 = uimenu( gui.FileMenu1, 'Label', 'Beenden', 'Callback', @onExit );
gui.FileMenu2 = uimenu( gui.Window, 'Label', 'Speichern' );
% Panel
gui.panel = uipanel('Units','normalized','Title','Panel','FontSize',10,'Position',[.01 .5 .25 .5]);
% Checkbox
for k=1:4
gui.checkbox{k} = uicontrol('parent',gui.panel,'Style','checkbox','string',data.Test_data(1*k),...
'Position',[10 350-k*20 150 20]);
end
% Listbox
for s=1:5
gui.Listbox_{s} = uicontrol('Style','listbox','Position',[300+200*s 400 120 100],'Visible','On');
end
% Button
for x=1:5
gui.Button_{x} = uicontrol('Style','pushbutton','Position',[300+200*x 500 120 40]);
end
% Axes
gui.axes = axes('Outerposition',[.335 .65 .05 .1],'Visible','Off');
% Arrow
h=annotation('textarrow','String','Test Arrow in Axes '); %%arrow, doublearrow, textarrow
set(h,'parent', gui.axes, 'position', [data.arrow_p1,data.arrow_p2], ...
'HeadLength', 5, 'HeadWidth', 5, 'HeadStyle', 'vback2', ...
'Color', [0 0 0], 'LineWidth', 0.5);
end
end

Accepted Answer

Jan
Jan on 21 Jun 2018
If you set the units of an UI-element to 'normalized', it's size changes, when the size of the parent object changes. To get a fixed position use any other units, e.g. 'pixels'.
  1 Comment
Pi Height
Pi Height on 21 Jun 2018
Thank you very much. It works perfect.
Could you tell me as well how to set it to a full screen?
I tried this, too:
gui.Window = figure('Name','Test','NumberTitle','off',...
'MenuBar','none');
WindowAPI(gui.Window, 'full'); % fill the current monitor
But unfortunatly it´s not working. I would like to use the size of the screen to reference the position of the objects.
To do so I use this:
pos1 = getpixelposition(gui.Window,true)
pos2 = get(0,'ScreenSize')

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks 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!