Placing radiobuttons with relative locations

10 ビュー (過去 30 日間)
Ryan1234321
Ryan1234321 2020 年 1 月 20 日
コメント済み: Robert U 2020 年 1 月 22 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by