I am currently trying to create a gui in GUIDE. I have created 2 tabs using uitab in a uitabgroup. I have 2 panels, of which 1 is changing when you switch between tabs (panel P1a and P1b). The other should remain the same (P2). My question is, how can I see panel P2 in both tabs? Code is as follows:
handles.tgroup = uitabgroup('Parent', handles.figure1)
handles.tab1 = uitab('Parent', handles.tgroup, 'Title', 'Import Text')
handles.tab2 = uitab('Parent', handles.tgroup, 'Title', 'Import Excel')
set(handles.P1a,'Parent',handles.tab1)
set(handles.P2,'Parent',handles.tab1)
set(handles.P1b,'Parent',handles.tab2)
set(handles.P2,'Parent',handles.tab2)
Currently, this code does not work, since I only connect P2 to tab2 because of the last line.
Thanks, Reinier

 채택된 답변

Adam
Adam 2016년 11월 4일

0 개 추천

Just reparent it in the 'SelectionChangedFcn' callback of the uitabgroup. It only needs to be parented by a tab if that tab is the currently selected one since you can never view 2 tabs at the same time.

댓글 수: 3

Reinier Tromp
Reinier Tromp 2016년 11월 4일
편집: Reinier Tromp 2016년 11월 4일
Thanks, that sounds like it should work. Is there a way to specify in GUIDE the SelectionChangedFcn callback of the uitabgroup? I am unsure how to code it in the current structure (usually callbacks are created automatically when I create the lay-out in GUIDE). Currently I have tried this (based on my previous code):
function tgroup_SelectionChangedFcn(hObject,eventdata,handles)
selectedTab = get(hObject,'SelectedTab');
if strcmp(selectedTab,'Import Text')==1
set(handles.P2,'Parent',handles.tab1)
elseif strcmp(selectedTab,'Import Excel')==1
set(handles.P2,'Parent',handles.tab2)
end
guidata(hObject,handles);
Adam
Adam 2016년 11월 4일
편집: Adam 2016년 11월 4일
Tabs are not supported in GUIDE so you have to do them programmatically, but I assume you have already created your uitabgroup programmatically anyway?
Something similar to this should work
hPanel = uipanel( ... )
hMainTabGroup = uitabgroup( ...
'Parent', hFig,...
'SelectionChangedFcn', @(src,evt) tabChangedCallback( evt, hPanel ) );
function tabChangedCallback( evtData, hPanel )
hPanel.Parent = evtData.NewValue;
end
Reinier Tromp
Reinier Tromp 2016년 11월 4일
Thank you so much, I managed to get it to work.
In GUIDE the last 'end' is not allowed though, fyi

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2016년 11월 4일

댓글:

2016년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by