title: MATLAB: Automatic resizing of GUI components/fonts
body: <p>I am having problems in trying to make my MATLAB GUIs <strong>automatically resizeable</strong>. 
  After exhaustively searching the web for help and lots of testing, I could not find out a solution. </p>
  
  <p>I have been developing a simple GUI (with MATLAB, <em>without using GUIDE</em>) in my laptop (<strong>Screen size/resolution = 1366x768</strong>). A very simplified version looks like this:</p>
  
  <h2><img src="https://i.stack.imgur.com/VVFyz.png" alt="GUI displayed in the laptop"></h2>
  
  <p>When I run the same GUI in my desktop computer (<strong>Screen size/resolution = 1920x1080</strong>), it shows in the following way:</p>
  
  <h2><img src="https://i.stack.imgur.com/o59uI.png" alt="GUI displayed in the desktop"></h2>
  
  <p>The dimensions of the GUI are automatically initialized taking into account the screensize (<strong><em>the code is provided in the bottom of this post</em></strong>). As you can see (highlighted by the red arrows), the fonts/spacing between components do not automatically resize so that the GUI has the same aspect no matter where we run the file.</p>
  
  <p>Additionally, when the GUI is manually resized, some overlap of the components occurs:</p>
  
  <h2><img src="https://i.stack.imgur.com/LGzYP.png" alt="GUI displayed in the desktop - After manual resizing"></h2>
  
  <hr>
  
  <p>The code used for this minimal working example is the following:</p>
  
  <pre><code>function resizingGUIexample()
  
  %% SET UP GUI
  hdl.mainfig = figure(); 
  
  % MANAGE FIGURE DIMENSIONS -------------------------------------------------------------------------------------
  set(hdl.mainfig, 'Units', 'pixels');
  dims              = get(0, 'ScreenSize');
  screenHeight      = dims(4);
  verticalMargins   = floor((0.2*screenHeight)/2);          % =10% of the screen height in each side
  figureHeight      =       (0.8*screenHeight);
  figureWidth       =       (0.8*screenHeight)*(4/3);       % 4/3 Aspect Ratio
  set(hdl.mainfig, 'Position', [0, verticalMargins, ... 
                  figureWidth, figureHeight]);
  
  movegui(hdl.mainfig,'center')     % move GUI to center
  
  color = get(hdl.mainfig,'Color'); % get background color to hide static texts, etc...
  
  % AXES ---------------------------------------------------------------------------------------------------------
  hdl.axes = axes('Parent',   hdl.mainfig,  ...
               'Units',   'Normalized', ...
            'Position',   [0.295 0.05 0.63 0.63*(4/3)]);
  
  % PUSH BUTTONS -------------------------------------------------------------------------------------------------
  hdl.donePB = uicontrol(hdl.mainfig,                          ...
                    'Position',   [0.85 0.91 0.075 0.075], ...
                      'String',   'Done',                  ...
                    'Fontsize',   16,                      ...
                       'Units',   'normalized',            ...
                  'FontWeight',   'Bold');
  
  % BUTTON GROUP and RADIO BUTTONS -------------------------------------------------------------------------------
  hdl.buttonGroup = uibuttongroup('Parent',    hdl.mainfig,  ...
                            'FontSize',    16,           ...
                          'FontWeight',    'Bold',       ...
                     'BackgroundColor',    color,        ...
                               'Units',    'Normalized', ... 
                            'Position',    [0.05 0.69 0.2 0.2]);
  titleBG = sprintf('Intensity\nNormalization');
  set(hdl.buttonGroup, 'Title', titleBG);
  
  hdl.VolumeRB = uicontrol(hdl.buttonGroup,                   ...
                               'Style',    'radiobutton', ...
                              'String',    'Volume',      ...
                            'FontSize',    14,            ...
                          'FontWeight',    'Bold',        ...
                               'Units',    'normalized',  ...
                     'BackgroundColor',    color,         ...
                            'Position',    [0.1 0.67 0.8 0.3]);
  
  hdl.SliceRB = uicontrol(hdl.buttonGroup,                   ...
                              'Style',    'radiobutton', ...
                             'String',    'Slice',       ...
                           'FontSize',    14,            ...
                         'FontWeight',    'Bold',        ...
                              'Units',    'normalized',  ...
                    'BackgroundColor',    color,         ...
                           'Position',    [0.1 .25 0.8 0.3]);
  
  end
  </code></pre>
  
  <p>Any ideas of how I can solve these issues?</p>
  
  <p>Thanks a lot in advance.</p>
  
  <p>Kind regards,</p>
  
  <p>Fábio Nery</p>
  
  <p><strong>EDIT1:</strong> I am also extremely open to suggestions for better ways to initialize the GUI dimensions and strategies for avoiding problems when running GUIs in different monitors/screen resolutions.</p>