I have several overlapping UIPanel's in AppDesigner and I want all but one panel to be hidden upon creation of the figure or soon thereafter. AppDesigner doesn't let you edit the constructor for the object and there is no property in the Component Browser for me to edit visibility. There is a .Visible property contained under app.panel.Visible that I believe can be set. Just can't figure out how to initialize this setting automatically without access to the constructor or the app creation.
MATLAB: AppDesigner UIPanel Hide Visibility
app designerguiguidematlab gui
Related Solutions
Us the TabGroupSelectionChanged callback function to set the visibility property of the panel to on/off. Here's what the code might look like if I only wanted to display the panel with Tab2 is visible.
% Selection change function: TabGroup
function TabGroupSelectionChanged(app, event) selectedTab = app.TabGroup.SelectedTab; switch selectedTab.Title case "Tab2" app.Panel.Visible = 'on'; otherwise app.Panel.Visible = 'off'; endend
I would have to set the visibility of the panel to the desired visibilty at launch using the inspector. There is a check box for visible in the Panel Interactivity section of the inspector.
(1) Two possibilities to reset your app to its default state:
I prefer the first. A simple example using a function called resetComponents:
classdef app1 < matlab.apps.AppBase % Properties that correspond to app components
properties (Access = public) UIFigure matlab.ui.Figure EditFieldLabel matlab.ui.control.Label EditField matlab.ui.control.EditField Button matlab.ui.control.Button end % Component initialization
methods (Access = private) % Create UIFigure and components
function createComponents(app) % Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off'); app.UIFigure.Position = [100 100 640 480]; app.UIFigure.Name = 'UI Figure'; % Create EditFieldLabel
app.EditFieldLabel = uilabel(app.UIFigure); app.EditFieldLabel.HorizontalAlignment = 'right'; app.EditFieldLabel.Position = [382 282 56 22]; app.EditFieldLabel.Text = 'Edit Field'; % Create EditField
app.EditField = uieditfield(app.UIFigure, 'text'); app.EditField.Position = [453 282 100 22]; % Create Button
app.Button = uibutton(app.UIFigure, 'push'); app.Button.Position = [129 282 100 22]; app.Button.Text = 'Reset'; app.Button.ButtonPushedFcn = @app.resetButtonCallback; % Show the figure after all components are created
app.UIFigure.Visible = 'on'; end function resetComponents(app) % Create EditFieldLabel app.EditFieldLabel = uilabel(app.UIFigure); app.EditFieldLabel.HorizontalAlignment = 'right'; app.EditFieldLabel.Position = [382 282 56 22]; app.EditFieldLabel.Text = 'Edit Field'; % Create EditField app.EditField = uieditfield(app.UIFigure, 'text'); app.EditField.Position = [453 282 100 22]; % Create Button app.Button = uibutton(app.UIFigure, 'push'); app.Button.Position = [129 282 100 22]; app.Button.Text = 'Reset'; app.Button.ButtonPushedFcn = @app.resetButtonCallback; % Or, alternatively, instead of redefining each component, just figure out all
% properties which could be changed by the user and reset them to their
% defaults:
%
% app.EditField.Value = '';
% % Simpler here, but takes more work for more complicated apps.
end function resetButtonCallback(app, ~, ~) resetComponents(app); end end % App creation and deletion
methods (Access = public) % Construct app
function app = app1 % Create UIFigure and components createComponents(app) % Register the app with App Designer
registerApp(app, app.UIFigure) if nargout == 0 clear app end end % Code that executes before app deletion
function delete(app) % Delete UIFigure when app is deleted
delete(app.UIFigure) end endend
(2) You can access a callback function if you have access to an instance of the app and you are calling from a location allowed by the function's Access attribute (e.g. Public, Private, etc).
Example 1: You cannot call a callback function from within a static method, because the static method does not have access to an instance of the app.
Example 2: You cannot call a callback function externally if its Access attribute is Private.
Best Answer