MATLAB: Uitab Position doesn’t update unless drawnow is called while the parent figure is visible

drawnowinheritinnerpositionMATLABoffonposition;uitabuitabgroupuitablevisible

I have a figure created with figure(). Within it I have a uitabgroup() that has a uitab() and a uitable() put in the tab. I'm trying to set the position of the table to fit properly within the uitab. What I have discovered is that if I set the size of the uitabgroup, uitab is supposed to inherit properties (uitab.Position is read only) so then I can size uitable to fit within uitab.Position and have clean edges on my objects. I'd like to be able to do this with the overall figure visibility OFF so people don't see the jumping around of components while I move and shape stuff.
Here's the basics of what I made:
d = figure('Visible','off');
method_tab_holder = uitabgroup('Parent',d);
method_tab = uitab('Parent',method_tab_holder);
method_table = uitable('Parent',method_tab);
The problem is that the uitab doesn't inherit any Position properties until a drawnow is called while the uitab is visible.
Here's a bit of stuff I did to follow the process. I check the values after creation but before positioning, after positioning but before drawnow calling, and after calling drawnow:
before_position_changes = [method_tab_holder.InnerPosition ; method_tab.InnerPosition ; method_table.Position]
after_position_changes = [method_tab_holder.InnerPosition ; method_tab.InnerPosition ; method_table.Position]
afterDrawNow_position_changes = [method_tab_holder.InnerPosition ; method_tab.InnerPosition ; method_table.Position]
This returns the following:
before_position_changes =
1 1 300 400
1 1 300 400
20 20 300 300
after_position_changes =
5 5 200 300
1 1 300 400
5 5 190 290
afterDrawNow_position_changes =
5 5 200 300
1 1 300 400
5 5 190 290
But if I run them with Visible turned on
d.Visible = 'on';
drawnow
I get this where method_tab has properly inherited size after the drawnow
before_position_changes =
1 1 300 400
1 1 300 400
20 20 300 300
after_position_changes =
5 5 200 300
1 1 300 400
5 5 190 290
afterDrawNow_position_changes =
5 5 200 300
3 4 195 270
5 5 190 290
As I said above, I can work around this BUT it is tiresome because I like to keep figures hidden until their layout is set so people don't see stuff jump around on their screen. Also, making the uitabgroup visible while the parent figure is invisible does't solve it – it appears it has to be rendered on screen before the Position properties inherit properly. Anyone know a workaround so I don't need to make stuff visible while setting positions?

Best Answer

Did you try to create the figure with enabled visibility but outside the visible scrren?
d = figure('Visible','off');
origPos = d.Position;
d.Position = origPos - [0, 2000, 0, 0];
d.Visible = 'on';
... Your code here until the figure is created.
d.Position = origPos;