How to programmatically select a tab in a uitabgroup?

25 ビュー (過去 30 日間)
Gary
Gary 2014 年 12 月 10 日
編集済み: Joseph Reynolds 2025 年 1 月 7 日
Is it possible to programmatically select one of the tabs in a uitabgroup? In response to a user request, I need to recreate the tabs and their contents, but I'd like to keep the original choice of tab. When the tabs are created, tab 1 is always selected.
tabgroup.SelectedTab is a read-only property; I tried writing to it (on the chance that it would work) and nothing happened.
Thanks!

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 12 月 10 日
You can set it using SelectedTab of the uitabgroup:
tg = uitabgroup;
tt(1) = uitab('Parent',tg);
tt(2) = uitab('Parent',tg);
tt(3) = uitab('Parent',tg);
tg.SelectedTab = tt(2);
(R2014b)
  2 件のコメント
Gary
Gary 2014 年 12 月 10 日
編集済み: Gary 2014 年 12 月 10 日
You're quite right. That's exactly what I tried before, but looks like I made a typographical error. So in spite of the documented read-only status of the SelectedTab property, this does work.
Thanks.
Sean de Wolski
Sean de Wolski 2014 年 12 月 10 日
You're welcome!
Yes, it needs to be set to the tab, not the number
tg.SelectedTab = 2
Would not work.

サインインしてコメントする。

その他の回答 (1 件)

Joseph Reynolds
Joseph Reynolds 2024 年 12 月 13 日
編集済み: Joseph Reynolds 2025 年 1 月 7 日
Matlab R2022a +/- some versions , You can use the Childeren of the TabGroup.
whith in an app there are two tabs in a given TabGroup, at the end of a function to go back to the first tab use the first index of the children, or the nth child if desired.
Syntax:
app.TabGroup.SelectedTab = app.TabGroup.Children(1);
For this example there are two tabs labeled:
  • Set Environment
  • Configure Environmen
>> app.TabGroup.Children
2×1 Tab array:
Tab (Set Environment)
Tab (Configure Environment)

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by