render tab in background
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
One of my app's tabs takes a while to render the first time you click on it. The code to create the contents of the tab has already executed, but the graphics has not been 'rendered', or something like that. I don't want the user to experience that delay. So at the moment, when the app starts, I draw the first tab, then programmatically change the tab to the 2nd (slow) tab, drawnow() (to force the graphics to render), then change back to the first/main tab. My goal here is to draw the 2nd tab in the background, preferably without the user realising, so there is no delay the first time the user clicks on it. It works reasonably well. The only remaining issue is that the app flashes briefly once it has finished drawing the second tab then switches back to the first tab. Is there some way to do this without that flash? That is, to "drawnow" without actually drawing? I have tried turning the visibility for the tabgroup off then on again, but it makes no difference to the flash. If I turn the window visibility off then on again, the window disappears for a second or two.
0 Kommentare
Antworten (1)
Abhiram
am 24 Apr. 2025
To avoid the app flashing when switching tabs, you can use the below code as a reference to implement a loading screen while pre-rendering the tabs.
% Create and show loading screen
app.LoadingPanel = uipanel(app.MainFigure);
app.LoadingPanel.Position = [0 0 app.MainFigure.Position(3:4)];
app.LoadingLabel = uilabel(app.LoadingPanel);
app.LoadingLabel.Text = 'Loading...';
app.LoadingLabel.Position = [app.LoadingPanel.Position(3)/2-40 app.LoadingPanel.Position(4)/2 80 22];
% Hide main content
app.MainTabGroup.Visible = 'off';
% Pre-render all tabs
app.MainTabGroup.SelectedTab = app.Tab1;
plot(app.Tab1Plot, rand(100,1)); % Example plot in Tab1
drawnow;
app.MainTabGroup.SelectedTab = app.Tab2;
scatter(app.Tab2Scatter, rand(1000,1), rand(1000,1), 'filled'); % Heavy plot in Tab2
drawnow;
% Return to first tab
app.MainTabGroup.SelectedTab = app.Tab1;
% Show main content and remove loading screen
app.MainTabGroup.Visible = 'on';
delete(app.LoadingPanel);
Hope this helps!
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!