Placing radiobuttons with relative locations

10 views (last 30 days)
How can I place buttons created by uicontrol() in a relative location, as opposed to absolute location, within a ui window?
It makes no sense to me that a uibuttongroup can be placed in a relative location, but the actual buttons can not. This is a problem when resizing a window.
For example, I can do:
button_group_1 = uibuttongroup('Visible','on','Position',[ 0.4 0 0.4 0.4 ]);
button_1 = uicontrol( button_group_1,'Style','radiobutton','String','button_1','Position',[ 10 50 100 50 ]);
But I can not do:
button_group_1 = uibuttongroup('Visible','on','Position',[ 0.4 0 0.4 0.4 ]);
button_1 = uicontrol( button_group_1,'Style','radiobutton','String','button_1','Position',[ 0.4 0 0.4 0.4 ]);
Could someone help me implement buttons in a relative position so that a window can be resized and their locations still make sense?

Accepted Answer

Robert U
Robert U on 20 Jan 2020
Hi Ryan1234321,
When creating GUIs by command without the use of GUIDE I do place all elements in absolute position. I take care that it fits well on my screen first. It is no problem to do so on any other machine, but GUI is going to be showed while all GUI elements are rescaled to a new window size.
My GUIs often contain a global variable "GUI" that is of type struct containing all figure handles where "GUI.fh" is the figure handle of the parent figure.
For changing the window size it is very effective to change the unit of fonts and general lengths into normalized:
function resize(~,~)
% Set all 'Units'-property within figure to 'normalized in order to
% allow for scaling
set(findall(GUI.fh,'Units','pixels'),'Units','normalized');
set(findall(GUI.fh,'FontUnits','points'),'FontUnits','normalized');
end
Thus, final lines in most GUIs are after building them the following:
drawnow();
resize();
set(GUI.fh,'ResizeFcn',@resize);
Kind regards,
Robert
  4 Comments
Ryan1234321
Ryan1234321 on 22 Jan 2020
Robert,
Thank you for your answer, I overlooked the ability to set the uibuttoncontrol's units to pixels and that I should pass the figure handle for the button group to the uicontrol() for the entry box.
The modifications you made worked very well.
Much appreciation,
Ryan
Robert U
Robert U on 22 Jan 2020
Thank you for your positive feedback. If you like my answer, please, vote for it by clicking on the "thumb up"-symbol.
In case it serves your needs and answers your question thoroughly, accept it.
Kind regards,
Robert

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!