I am still playing around with the uifigure
components. As I explained yesterday, I'm interested in understanding matlab.ui.container.GridLayout
to eventually use it as a base for some widgets.
But I experience the following behaviour when I derive a class from matlab.ui.container.GridLayout
, which I do not understand. I have tested this with R2019a (Linux) and R2019b (Win):
g = matlab.ui.container.GridLayout('Parent', uifigure()); b = uibutton(g)
In contrast, if I derive a class from matlab.ui.container.GridLayout
classdef MyGrid < matlab.ui.container.GridLayout
methods
function self = MyGrid ( varargin )
self = self@matlab.ui.container.GridLayout( varargin {:} );
end
end
end
and use
g = MyGrid('Parent', uifigure()); b = uibutton(g)
I get an empty figure:
Can anyone explain this behaviour and/or knows a way to show the Button in the case of the derived class?
Here is some more information:
- By setting a breakpoint in
matlab.ui.container.GridLayout.handleChildAdded
I see that this function is called in the case of adding the button to theMyGrid
instance - The size of
MyGrid
increases when the button is added:
>> g = MyGrid('Parent', uifigure());
>> g.RowHeight = {};
>> g.ColumnWidth = {}
g =
MyGrid with properties:
RowHeight: {}
ColumnWidth: {}
Show all properties
>> b = uibutton(g);
>> g
g =
MyGrid with properties:
RowHeight: {'1x'}
ColumnWidth: {'1x'}
Show all properties
- The buttom's
Visible
property ison
>> b.Visible
ans =
'on'
- The grid's
Visible
property ison
, too:
>> g.Visible
ans =
'on'
- The
Layout
property of the button is correct:
>> b.Layout
ans =
GridLayoutOptions with properties:
Row: 1
Column: 1
- The
Parent
properties are okay:
>> f = uifigure();
>> g = MyGrid('Parent', f);
>> b = uibutton(g);
>> b.Parent == g
ans =
logical
1
>> g.Parent == f
ans =
logical
1
- The
Children
properties are okay, too:
>> f.Children(1) == g
ans =
logical
1
>> g.Children(1) == b
ans =
logical
1