我在MATLAB中的GUI工作,我使用选项卡来组织信息.由于MATLAB指南中不支持选项卡,我只需创建几个uipanels并更改其“可见”字段.但是,当每个面板中的控件数量较多时,需要一些时间才能在面板之间切换.有没有人知道如何使标签切换更快?
我包括一个简单的基于Tab的界面的例子.
tab_example_gui.m
% Figure
handles.figure_window = figure(...
'Units','characters',...
'Tag','figure_window',...
'Position',[50 50 80 25],...
'Name','Tab Example',...
'DockControls','off',...
'IntegerHandle','off',...
'MenuBar','none',...
'NumberTitle','off',...
'Resize','off');
% Buttons
handles.tab_panel = uibuttongroup(...
'Parent',handles.figure_window,...
'Tag','tab_panel',...
'Units','characters',...
'Position',[0 23 80 2],...
'SelectionChangeFcn',@(hObject,eventdata)tab_example_callback(hObject,eventdata,guidata(hObject)),...
'BorderType','none');
handles.tab_a = uicontrol(...
'Parent',handles.tab_panel,...
'Tag','tab_a',...
'Units','characters',...
'Position',[0 0 40 2],...
'Style','togglebutton',...
'String','Tab A');
handles.tab_b = uicontrol(...
'Parent',handles.tab_panel,...
'Tag','tab_b',...
'Units','characters',...
'Position',[40 0 40 2],...
'Style','togglebutton',...
'String','Tab B');
% Panel A
handles.panel_a = uipanel(...
'Parent',handles.figure_window,...
'Tag','panel_menu',...
'Units','characters',...
'Position',[0.1 0 79.8 23],...
'Visible','On');
handles.panel_a_text = uicontrol(...
'Parent',handles.panel_a,...
'Tag','panel_menu_load_id_text',...
'Units','characters',...
'Position',[0 0 77 22],...
'Style','text',...
'String','This is the tab A');
% Panel B
handles.panel_b = uipanel(...
'Parent',handles.figure_window,...
'Tag','panel_menu',...
'Units','characters',...
'Position',[0.1 0 79.8 23],...
'Visible','Off');
handles.panel_b_text = uicontrol(...
'Parent',handles.panel_b,...
'Tag','panel_menu_load_id_text',...
'Units','characters',...
'Position',[0 0 77 22],...
'Style','text',...
'String','This is the tab B');
guidata(handles.figure_window, handles);
tab_example_callback.m
function tab_example_callback(hObject,eventdata,handles)
switch get(get(hObject,'SelectedObject'),'Tag')
case 'tab_a', set(handles.panel_a,'Visible','On'); set(handles.panel_b,'Visible','Off');
case 'tab_b', set(handles.panel_a,'Visible','Off'); set(handles.panel_b,'Visible','On');
end
guidata(handles.figure_window, handles);
end
注意:GUI是在5个选项卡中引入模拟参数.在每个选项卡中,我有大约15行;每行都有一个文本,一个复选框和三个编辑.对我来说看起来并不拥挤.此外,我已经使用最少的代码和开销自己做了布局和回调.但是,它仍然有非常烦人的标签转换.