How do you set the Layout Option at construction for ui objects?
27 ビュー (過去 30 日間)
古いコメントを表示
If I have a simple uifigure like:
fh = uifigure;
gl = uigridlayout(fh);
I can add a uicomponent (and specify where on the gridlayout it will sit) like:
btn = uibutton(gl, Text="Hello World");
btn.Layout.Row = 2;
btn.Layout.Column = 2;
Is it possible to set the layout options using the Layout property of the btn e.g.
btn = uibutton(gl, Text="Hello World", Layout=???);
Sending a struct like:
btn = uibutton(gl, Text="Hello World", Layout=struct('Row',2,'Column',2);
Gives the error:
Error setting property 'Layout' of class 'Button':
'Layout' value must be specified as a
matlab.ui.layout.LayoutOptions object.
But I can't seem to instantiate an instance of the class LayoutOptions as:
l = LayoutOption();
Gives the error:
Unrecognized function or variable 'LayoutOption'.
0 件のコメント
採用された回答
その他の回答 (1 件)
Umar
2024 年 6 月 28 日
Hi Rohan,
By using uilayout.GridLayoutOptions to create a LayoutOptions object, you can set the row and column properties before assigning it to the button's Layout property. Here's the corrected approach to set layout options for a button in a grid layout:
fh = uifigure;
gl = uigridlayout(fh);
% Create a LayoutOptions object
layoutOptions = uilayout.GridLayoutOptions;
layoutOptions.Row = 2; layoutOptions.Column = 2;
% Add a button with specified layout options
btn = uibutton(gl, 'Text', 'Hello World', 'Layout', layoutOptions);
Hope this answers your question.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!