I am working to translate a GUI from using raw positions of elements to using a grid layout. This really makes the code a bit simpler, but once I started testing I quickly noticed an issue with displaying plots.
My application involves showing many components in a single window, so scrolling is a necessity. Once I turn on scrolling, the plots seem to be pushed above the proper position by rows below. If the figure is resized big enough to display all components without scrolling, the axes will be back in the proper location.
- Is this a known error and can it be fixed please?
- Is there any workaround other than just not changing the positioning?
Here is some basic code which illustrates the issue:
curGrid = uigridlayout('Scrollable', 'off');
curLabel = uilabel(curGrid, 'Text', 'Label above');
curLabel.Layout.Row = 2;
curLabel.Layout.Column = [1,2];
curLabel.BackgroundColor = 'cyan';
curGrid.RowHeight = {250,'fit',100,400};
ax = axes(curGrid);
ax.Layout.Row = 3;
ax.Layout.Column = 1;
curLabelRight = uilabel(curGrid, 'Text', 'Label right');
curLabelRight.Layout.Row = 3;
curLabelRight.Layout.Column = 2;
curLabelRight.BackgroundColor = 'cyan';
curLabelBelow = uilabel(curGrid, 'Text', 'Label below');
curLabelBelow.Layout.Row = 4;
curLabelBelow.Layout.Column = [1,2];
curLabelBelow.BackgroundColor = 'cyan';
curGrid.Scrollable = true;
I have tested this in both MATLAB 2021b and 2022a with the same result.
Update:
I have found a potential workaround. If I put a uipanel into the desired location, then add the plot to the panel it stays where it should be. However, this results in showing a border around the plot which is not desired but isn't too bad.
panelRight = uipanel(curGrid);
panelRight.Layout.Row = 3;
panelRight.Layout.Column = 2;
In addition in 2021b, warnings are displayed when interacting with a plot inside the uigridpanel such as brushing data.
curGrid = uigridlayout('Scrollable', 'off');
curGrid.RowHeight = {250,'fit',100,400};
curLabel = uilabel(curGrid, 'Text', 'Label above');
curLabel.Layout.Row = 2;
curLabel.Layout.Column = [1,2];
curLabel.BackgroundColor = 'cyan';
ax = axes(curGrid);
ax.Layout.Row = 3;
ax.Layout.Column = 1;
plot(ax, [1,2,3],[2,5,6])
curLabelRight = uilabel(curGrid, 'Text', 'Label right');
curLabelRight.Layout.Row = 3;
curLabelRight.Layout.Column = 2;
curLabelRight.BackgroundColor = 'cyan';
curLabelBelow = uilabel(curGrid, 'Text', 'Label below');
curLabelBelow.Layout.Row = 4;
curLabelBelow.Layout.Column = [1,2];
curLabelBelow.BackgroundColor = 'cyan';
curGrid.Scrollable = true;
Warning: Error occurred while executing the listener callback for event Action defined for class
matlab.graphics.interaction.graphicscontrol.AxesControl:
Error using matlab.ui.container.GridLayout/get
No public property 'Position' for class 'GridLayout'.
Error in matlab.graphics.interaction.uiaxes.DataTipsBase
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipHoverLingerInteraction/handleEvent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.DataTipBaseInteraction/response
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase/responseevent
Error in matlab.graphics.interaction.graphicscontrol.InteractionObjects.InteractionBase
Error in matlab.graphics.interaction.graphicscontrol.GenericControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.LayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.layoutable.GridLayoutableControl/process
Error in matlab.graphics.interaction.graphicscontrol.AxesControl/process
Error in matlab.graphics.interaction.graphicscontrol.ControlManager/processMessage
> In matlab.graphics.interaction.graphicscontrol/GenericControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/LayoutableControl/process
In matlab.graphics.interaction.graphicscontrol.layoutable/GridLayoutableControl/process
In matlab.graphics.interaction.graphicscontrol/AxesControl/process
In matlab.graphics.interaction.graphicscontrol/ControlManager/processMessage
Also, I tested this in MATLAB 2022b and found this is no longer an issue. However, the axes still jump around a bit while resizing. This behavior is much improved when using the uipanel workaround.