Is it possible to hide the entire check box, then make it visible when conditions are met? I know I can have no text, then set that text when a condition is met, but can this be done for the actual checkbox part?
MATLAB: GUI checkbox set visibility
gui
Related Solutions
First of all, I think you should use a togglebutton, as with a pushbutton the edit box would go invisible as soon as you let go of the mouse button.
for the button callback:
if get(hObject,'Value') set(handles.editTag,'Visible','On')else set(handles.editTag,'Visible','Off')end
Where editTag is the Tag of your edit button (The default is edit1)
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.
- 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.
- 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;endend
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.
- From within app designer, add the tab group to the app.
- 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.
- Add a check box.
- Right click the checkbox, go down to "callbacks" and select "Add ValueChangedFcn". That will add a function in code-view.
- 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.
- Save the app and test it.
value = app.CheckBox.Value;if value app.TabGroup.Visible = 'on'; else app.TabGroup.Visible = 'off';end
Best Answer