Switching SelectedTab by WindowKeyPressFcn successively

I want to switch uitab using WindowKeyPressFcn as the attached code. If the last clicked object is outside of the tab group (white area), pressing 1 and 2 on the keyboard successively switches selectedTab as I want. However, if the inside of the tab group (gray, red or green area) were clicked last, the tab can not be switched with the keyboard after switching one time.
Is there any solutions?
Thank you.

 Réponse acceptée

Mahato Endo
Mahato Endo le 21 Nov 2017

1 vote

It might be an unexpected behavior of “WindowKeyPressFcn”. You can report the behavior to the MathWorks technical support team directly. https://jp.mathworks.com/support/servicerequests/index.html

1 commentaire

Yuki
Yuki le 22 Nov 2017
Thank you for your comment. I will ask to the support center.

Connectez-vous pour commenter.

Plus de réponses (1)

Yuki
Yuki le 22 Nov 2017
Modifié(e) : Yuki le 22 Nov 2017

1 vote

I got a reply from support center. If we focused on existing uicontrol object or a dummy object in tab, the problem never happen. I heared also that they will try to update WIndowKeyPressFcn itself.
>> lines are modifications from support center.
--------------------------------------------------------------------------------
function h=test_slcttab
h.fig=figure('WindowKeyPressFcn',@WindowKeyPressFcn_fig,'Color',[1 1 1]);
h.tg=uitabgroup(h.fig,'Position',[0 0 1 2/3]);
h.tb1=uitab(h.tg,'Title','t1','BackgroundColor',[1 0 0]);
>> h.control1 = uicontrol( h.tb1, 'Style', 'Text', 'Position', [0 0 0 0] );
h.tb2=uitab(h.tg,'Title','t2','BackgroundColor',[0 1 0]);
>> h.control2 = uicontrol( h.tb2, 'Style', 'Text', 'Position', [0 0 0 0] );
function WindowKeyPressFcn_fig(~,N1_in2)
if strcmp(N1_in2.Key,'1')
h.tg.SelectedTab=h.tb1;
>> uicontrol(h.control1)
elseif strcmp(N1_in2.Key,'2')
h.tg.SelectedTab=h.tb2;
>> uicontrol(h.control2)
end
end
end
--------------------------------------------------------------------------------
Thank you.

Catégories

Community Treasure Hunt

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

Start Hunting!