Clear Filters
Clear Filters

Adding axes to a scrollable gridlayout displays in the wrong location

17 views (last 30 days)
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.
  1. Is this a known error and can it be fixed please?
  2. Is there any workaround other than just not changing the positioning?
Here is some basic code which illustrates the issue:
curGrid = uigridlayout('Scrollable', 'off'); %Also has the problem if scrollable is initially 'on'
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';
%Once set to scrollable, position of the axes is pushed up by rows outside
%the figure
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;
ax = axes(panelRight);
In addition in 2021b, warnings are displayed when interacting with a plot inside the uigridpanel such as brushing data.
curGrid = uigridlayout('Scrollable', 'off'); %Also has the problem if scrollable is initially 'on'
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]) %Attempting to brush this data in the figure shows a warning in the command window
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';
%Once set to scrollable, position of the axes is pushed up by rows outside
%the figure
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.

Accepted Answer

Raghunathraju
Raghunathraju on 1 Mar 2023
Hi Ben,
As per my understanding, you want display axes in a specific position in uigridlayout. But you are unable to get the desired output as the position is changing while you tested that in 2021b and 2022a.
I tried to reproduce the same in 2021b and I got the same result i.e., the change in position of axes. But in 2022a the issue is not persisting.
I think the issue is fixed in the latest update of R2022a.So, Kindly update to latest version of R2022a.
The workaround you found using uipanel will assure that the position remains same. You can use that as well.
For more information, go through the MATLAB Documentation.
  1 Comment
Ben Brust
Ben Brust on 3 Mar 2023
Interesting, when I tested in 2022a it was still there. However 2022b seemed to resolve the steady state operation.
I still noted the axes jumping around during the scroll in 2022b on my machine.
In light of these issues, I plan to go back to fixed positioning and transition to uihtml in the future.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!