而不是创建一个新的图形,而是传递要嵌入代码的父对象。例如,(假设您使用了链接问题的接受答案代码):
function tab_gui1(parent)
hTabGroup = uitabgroup('Parent', parent); % parent here is the main GUI figure.
hTabs(1) = uitab('Parent', hTabGroup, 'Title', 'Data');
hTabs(2) = uitab('Parent', hTabGroup, 'Title', 'Params');
hTabs(3) = uitab('Parent', hTabGroup, 'Title', 'Plot');
set(hTabGroup, 'SelectedTab', hTabs(1));
... Rest of Code is the same
end
然后将父对象传递给子 GUI 函数:
function test_embeddedGUI()
hFig = figure('Menubar', 'none');
tab_gui1(hFig); % your parent object being passed is the main figure.
uicontrol('Style', 'pushbutton', 'String', 'This is a simple test', 'Callback', @testButton);
function testButton(src, evt)
disp('button was pressed');
end
end
然而,通过这种特殊的安排,您可以获得可以/将重叠的元素:
请注意,按钮是重叠的。根据我从您的问题中收集到的信息,您似乎希望有一个表格主界面,每个选项卡都有子界面。我建议在主 GUI 上创建选项卡式界面,然后为每个选项卡创建一个uipanel。然后,您将使用单独的函数填充这些 uipanel。这是一个简单的例子:
主界面
function test_embeddedGUI()
hFig = figure('Menubar', 'none');
hTabGroup = uitabgroup('Parent', hFig);
hTabs(1) = uitab('Parent', hTabGroup, 'Title', 'First');
hTabs(2) = uitab('Parent', hTabGroup, 'Title', 'Second');
hTabs(3) = uitab('Parent', hTabGroup, 'Title', 'Third');
set(hTabGroup, 'SelectedTab', hTabs(1));
firstPanel = uipanel('Title', 'Main Panel', 'Parent', hTabs(1));
secondPanel = uipanel('Title', 'Secondary Panel', 'Parent', hTabs(2));
thirdPanel = uipanel('Title', 'Final Panel', 'Parent', hTabs(3));
subUI1(firstPanel);
end
子界面:
function subUI1(parent)
firstButton = uicontrol('Style', 'pushbutton', 'String', 'First Button' ...
, 'Parent', parent, 'Callback', @buttonPress);
function buttonPress(src, evt)
disp('Main Button press');
end
end
这将创建一个像这样的界面: