MATLAB Answers

GUI Resizing Issue for Different Screen Resolutions

7 views (last 30 days)
SWAROOP HP on 5 Feb 2019
Commented: Luna on 12 Feb 2019
I have created a programmatic GUI in Matlab R2016a. The GUI was created on desktop with screen resolution 1920x1200. Although I have chosen units as 'normalized' for all the components created, the components are not getting resized proprtionallly when used with different screen resolutions. Is it really necessary to write a SizeChangedFcn to accomodate different screen resolution or is there any easy way forward?


Sign in to comment.

Answers (1)

Luna on 5 Feb 2019
The best, easiest and effortless way to do it is using GUI Layout Toolbox from FEX.
You will never need to implement SizeChangedFcn to all your components.
Put your ui elements inside the containers which are created by uix or uiextrax class as children.
figHandle = figure;
ButtonBox = uix.HButtonBox('Parent',figHandle,'ButtonSize',[100 50]); % Creates Horizontal Button Box, each button you created below put horizontally
buttonHandle1 = uicontrol('Parent',ButtonBox,'Style','pushbutton','String','OK');
buttonHandle2 = uicontrol('Parent',ButtonBox,'Style','pushbutton','String','Cancel');
There are other options for both vertical and horizontally as boxes, panels, etc..
You can read the documentation.


Show 4 older comments
SWAROOP HP on 12 Feb 2019
I need some help in positioning the uitable inside a uix.panel. I am trying to position the uitable by specifying position property [x y w h], but it is not working, table is getting created at the top left corner in the parent component. Find the code below.
Also I wanted to know wheteher the table size gets adjusted according to different resolutions, if it is placed inside a uix.Panel.
p1=uix.Panel( 'Parent',f);
RowName = {'A','B','C','D','E','F','G',...
Data = zeros(9,1);
'units','normalized','Position',[0.2 0.55 0.45 0.38],...
Adam on 12 Feb 2019
Place it inside either a uix.HBox or uix.VBox layout that is parented by the panel. Then it will automatrically resize with the panel. You can use uix.Empty to provide padding if you want or multiple HBox or VBox layouts to put other components in too if you need.
If you make a panel that is just for the table though then the table can fill that whole panel within a layout.
Luna on 12 Feb 2019
Just addition what Adam said, you can also use HBox's Width property and VBox's Heights property to resize what number of elements you put in that Box.
For example if you have 3 items in your VBox:
myItemsVBox.Heights = [-1, -3, -3]; % that makes 1st element 3x times narrower than the last two.
% same for HBox.
% Just be sure that you create the vector same size of the element number.
Also you can use VBoxFlex and HBoxFlex that allows you to resize with mouse.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by