How to hide a uitab with RadioButtonGroup?

3 views (last 30 days)
T B
T B on 17 May 2021
Commented: T B on 17 May 2021
If I create my tab, some functions need much time. Because the user shouldn't see a half-finished tab, i hide the tab with
app.Tab1.Parent = [];
and unhide the tab at the end with
app.Tab1.Parent = app.TabGroup;
For the most objects, this procedure works fine. Now I added a RadioButtongroup and noticed that the group isn't visible.
Here is a possible Gui to recreate the problem:
classdef testgui < matlab.apps.AppBase
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
tab_a matlab.ui.container.Tab
tab_b matlab.ui.container.Tab
NormalButton matlab.ui.control.Button
ButtonGroup matlab.ui.container.ButtonGroup
RButton1 matlab.ui.control.RadioButton
RButton2 matlab.ui.control.RadioButton
UIAxes matlab.ui.control.UIAxes
WelcomeLabel matlab.ui.control.Label
end
methods (Access = public)
function app = testgui(app)
app.start_app_tab_a()
pause(1)
app.create_tab_b()
app.tab_b.Parent = app.TabGroup;
app.TabGroup.SelectedTab = app.tab_b;
end
function app = start_app_tab_a(app)
app.UIFigure = uifigure();
app.UIFigure.Position = [100 100 800 500];
app.UIFigure.Name = 'UI Figure';
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [1 1 800 500];
app.TabGroup.Visible = "on";
app.tab_a = uitab(app.TabGroup);
app.tab_a.Title = "Tab A";
app.WelcomeLabel = uilabel(app.tab_a);
app.WelcomeLabel.Position = [250 250 200 20];
app.WelcomeLabel.Text = 'Wait here until Tab B looks fine';
end
function app = create_tab_b(app)
app.tab_b = uitab(app.TabGroup);
app.tab_b.Title = "Tab B";
% the Problem?
app.tab_b.Parent = [];
% Create UIAxes
app.UIAxes = uiaxes(app.tab_b);
app.UIAxes.Position = [200 200 400 250];
% pause = other functions
pause(3)
plot(app.UIAxes,randi(5,20,1),randi(5,20,1))
app.NormalButton = uibutton(app.tab_b, 'push');
% Button.ValueChangedFcn = createCallbackFcn(app, @ButtonPshued, true);
app.NormalButton.Position = [300 100 80 25];
app.NormalButton.Text = 'Button0';
%create RadioButtongroup
app.ButtonGroup = uibuttongroup(app.tab_b);
app.ButtonGroup.Position = [400 100 100 90];
app.RButton1 = uiradiobutton(app.ButtonGroup);
app.RButton1.Text = 'Option A';
app.RButton1.Position = [5 50 90 20];
app.RButton2 = uiradiobutton(app.ButtonGroup);
app.RButton2.Text = 'Option B';
app.RButton2.Position = [5 20 90 20];
app.RButton2.Value = true;
app.RButton1.Value = false;
end
end
end
If I delete this line
app.tab_b.Parent = [];
the user see the RadioButtonGroup, but the user could change the selected tab manually, before tab b is finished. The main question is, why do the radiobuttons disappear if I change the parent of the tab?

Accepted Answer

T B
T B on 17 May 2021
If
tab.Parent = TabGroup
then the default is
app.ButtonGroup.Units = "pixels"
and if
tab.parent = []
then the default is
app.ButtonGroup.Units = "normalized"
Therefore the position [400 100 100 90] wasn't in the visible range. But why is Matlab doing this?
The solution of the problem is:
app.ButtonGroup = uibuttongroup(app.tab_b);
app.ButtonGroup.Units = "pixels";
app.ButtonGroup.Position = [400 100 100 90];

More Answers (1)

Geoff Hayes
Geoff Hayes on 17 May 2021
Why not just hide or show the tab using the Visible property? For example, you could do
app.TabGroup = uitabgroup(app.UIFigure);
app.TabGroup.Position = [1 1 800 500];
app.TabGroup.Visible = false; % <----- hide the TabGroup
and then show it with
app.TabGroup.Visible = true;
Or maybe I'm misunderstanding what you are trying to accomplish?
  5 Comments
Geoff Hayes
Geoff Hayes on 17 May 2021
That seems* like a bug then.
Have you seen Adam's answer from https://www.mathworks.com/matlabcentral/answers/550827-matlab-gui-tabgroup-visibility-checkbox#comment_904678 where it is suggested that you can prevent navigation to certain tabs using the SelectionChangedFcn? I suppose that you could do the same and then only allow navigation until that tab until is is ready.
T B
T B on 17 May 2021
thanks for your efforts. The problem was related to the units.

Sign in to comment.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!