Matlab GUI - Tabgroup visibility - checkbox

Hi everyone, for a project in university i am creating a gui for an animation and i have a question.
I would like to activate and deactivate a tab group with a checkbox (by default it should be hidden).
During my research in the forum i came across the following:
(from Jorge Paloschi on 5 Jun 2020 at 16:41 - https://de.mathworks.com/matlabcentral/answers/355804-app-designer-tab-groups)
  • Create a dummy
tg = matlab.ui.container.TabGroup;
  • Suppose your tab is in index 2, then do
app.TabGroup.Children(2).Parent = tg;
  • After this the tab is not visible anymore
  • To make it visible again do the opposite
tg.Children(1).Parent = app.TabGroup;
  • The only remaining action is to permute the children of app.TabGroup so that the last Children goes back to index 2, and voila, visible again in the right order!
You might have to change the property name TabGroup to the one in your application if it is not the default Property name."
But I dont understand how it works and i want to disable all by default. Could anybode help me pls?

1 commentaire

Adam Danz
Adam Danz le 18 Juin 2020
Are you trying to make the entire tab group not visible (which my answer does) or are you trying to control the visibility of each tab?

Connectez-vous pour commenter.

 Réponse acceptée

Adam Danz
Adam Danz le 18 Juin 2020
Modifié(e) : Adam Danz le 19 Juin 2020
Control tab selectivity
As of r2020a, there isn't an option to set the visibility or 'enable' property of a tab. However, you can control which tabs can be selected according to a set of checkboxes via the use of a SelectionChangedFcn.
  1. From App designer > Design View, right click the top of the Tab Group (not an individual Tab but the entire group). Go down to 'callbacks' and select "Add SelectionChangedFcn". This will add a function in Code View.
  2. Within the SelectionChangedFcn, determine if the most recently selected tab is associated with a checked or un-checked checkbox. If checked (or unchecked), return the active tab to the previously selected tab. This will prevent the user from selecting tabs associated with checked (or unchecked) check boxes.
This demo restricts tab selection if the checkbox is checked. You can easily do the opposite by changing the conditional statement at the end of the function below.
The SelectionChangedFcn will look like this, below (the entire app is also attached).
% Selection change function: TabGroup
function TabGroupSelectionChanged(app, event)
% Determine which tab was selected
selectedTab = app.TabGroup.SelectedTab;
% Look up the value of the paired checkbox
% Each "case" is the title of a Tab and contains the pair checkbox.
switch selectedTab.Title
case 'Tab'
checkboxValue = app.CheckBox.Value;
case 'Tab2'
checkboxValue = app.CheckBox2.Value;
case 'Tab3'
checkboxValue = app.CheckBox3.Value;
otherwise
error('Unknown tab: %s.',selectedTab.Title)
end
% If paired checkbox is checked, return to the previously selected tab
if checkboxValue % --OR-- if ~checkboxValue
app.TabGroup.SelectedTab = event.OldValue;
end
end
To toggle the visibility of the entire Tab Group
Here are instructions that sets the visibility of the entire tab group based on a checkbox value.
  1. From within app designer, add the tab group to the app.
  2. Select the added tab group from the top (not the tab but the entire group) and then go to the component browser on the right. Under "Interactivity" you should see a checkbox for "Visible". If you want the default to be off, de-select that.
  3. Add a check box.
  4. Right click the checkbox, go down to "callbacks" and select "Add ValueChangedFcn". That will add a function in code-view.
  5. The selected/de-selected value of the checkbox is stored in app.CheckBox.Value (or whatever your checkbox handle name is). Add the code below within that function. You'll need to substitute the app variables with your correct handle names.
  6. Save the app and test it.
value = app.CheckBox.Value;
if value
app.TabGroup.Visible = 'on';
else
app.TabGroup.Visible = 'off';
end

7 commentaires

Philipp G.
Philipp G. le 19 Juin 2020
First of all thank you very much for your quick feedback!
No, i try to activate and deactivate single tab group elements by checkboxes.
Adam Danz
Adam Danz le 19 Juin 2020
I've updated my answer with a solution.
In short, you can't make the tabs disappear but you can control if they are selected or not.
Philipp G.
Philipp G. le 19 Juin 2020
Modifié(e) : Voss le 30 Oct 2024
Holy [redacted]! Insane dude...
Thank you very much for your more than detailed answer! Maybe i should ask questions in the forum more often in the future instead of searching for hours :D
Adam Danz
Adam Danz le 19 Juin 2020
Modifié(e) : Adam Danz le 19 Juin 2020
Glad I could help!
Actually, you did the right thing by searching for an answer first. The vast majority of questions asked are not original questions and their answers exist already in the forum or a close-enough answer exists that can be adapted.
It's usually much quicker to search for an answer for 15-20 minutes before putting 10+ minutes into writing a well thought-out question, exchanging commentary for hours or days, and then being fortunate enought to be among the ~50% of questions to actually get an answer, if it even works for your problem, and then spend a day or two understanding it. :D
But in this case, you did ask a very unique and interesting question. I found only 1 other topic in this forum related to this question and it didn't really address the problem. So thanks for the original question!
Michael
Michael le 1 Nov 2023
Modifié(e) : Michael le 2 Nov 2023
It looks like this is still not a feature as of 2023b - is there any plan to add this? It does seem like an omission. I would like to be able to enable/disable tabs (not so worried about tab visibility) depending on an arbitrary action, for example pushing a button.
Can this example be extended to allow a general 'enabling/disabling' function for tabs that can be called from callback functions and checks the logical status of enable flags for each tab?
JClarcq
JClarcq le 3 Nov 2023
I agree with Michael. Acutally I would like to have both enable and visible properties for each tab within a tab group.
Olof
Olof le 30 Oct 2024
I agree with JClarcq - both enable and visible properties for each tab within a tab group

Connectez-vous pour commenter.

Plus de réponses (1)

audrey b
audrey b le 18 Fév 2023

0 votes

Unrecognized property 'Visible' for class 'matlab.ui.container.Tab'. im facing for this error and ive no idea what am i doing wrong T.T pls help
function TabGroupSelectionChanged(app, event)
selectedTab = app.TabGroup.SelectedTab;
switch selectedTab
case app.Step1Tab
app.Step1Tab.Visible = 'on';
app.Step2Tab.Visible = 'off';
app.Step3Tab.Visible = 'off';
case app.Step2Tab
app.Step1Tab.Visible = 'off';
app.Step2Tab.Visible = 'on';
app.Step3Tab.Visible = 'off';
case app.Step3Tab
app.Step1Tab.Visible = 'off';
app.Step2Tab.Visible = 'off';
app.Step3Tab.Visible = 'on';
end
end

1 commentaire

Read the first sentence of the accepted answer: this feature is not supported from R2020a

Connectez-vous pour commenter.

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by