我正在尝试使用uifigure(以编程方式,而不是appdesigner[但我已将其添加为关键字,因为它是相关的])开发我的第一个 GUI,并且(如预期的那样)我缺少一些由提供的扩展功能和小部件用于标准 java 图形的GUI 布局工具箱和小部件工具箱。
因此,我尝试将一些我开发的小部件更改为,并且从 GUI 布局工具箱中替换uifigure和uigridlayout似乎非常方便。uix.VBoxuix.HBox
对于标准的 java 图形,假设我有一个类MyWidget和它的相应实例mywidget。MyWidget最后,它的祖先matlab.ui.container.internal.UIContainer会提供一种addChild方法,该方法可以被覆盖以自定义行为
uicontrol(mywidget)
我正在寻找相同的uifigure组件。假设从 派生的以下类matlab.ui.container.GridLayout,它是uigridlayout调用结果的类。
classdef MyGrid < matlab.ui.container.GridLayout
methods
function self = MyGrid(varargin)
self = self@matlab.ui.container.GridLayout(varargin{:});
end
end
methods ( Access = protected )
function addChild(self, child)
disp('hooray');
addChild@matlab.ui.container.GridLayout(self, child);
end
end
end
当我现在启动一个MyGrid实例时
g = MyGrid()
一切看起来都很好:
g =
MyGrid with properties:
RowHeight: {'1x' '1x'}
ColumnWidth: {'1x' '1x'}
但添加一个孩子不会调用该addChild方法:
>> uibutton(g)
ans =
Button (Button) with properties:
Text: 'Button'
Icon: ''
ButtonPushedFcn: ''
Position: [100 100 100 22]
注意:hooray以上没有输出。Parent属性是正确的:
>> ans.Parent
ans =
MyGrid with properties:
RowHeight: {'1x' '1x'}
ColumnWidth: {'1x' '1x'}
Show all properties
据此,我猜这addChild不是(至少是matlab.ui.container.GridLayout)用来添加孩子的方法。
有谁知道将子元素添加到uifigure组件中的容器的机制?