Placing radiobuttons with relative locations

9 次查看(过去 30 天)
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?

采纳的回答

Robert U
Robert U 2020-1-20
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 个评论
Ryan1234321
Ryan1234321 2020-1-22
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 2020-1-22
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by