2

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)

enter image description here

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:

enter image description here

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 the MyGrid 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 is on
>> b.Visible

ans =

    'on'
  • The grid's Visible property is on, 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
Patrick Happel
  • 1,336
  • 8
  • 18
  • I deleted my answer since it didn't solve your problem. Next thing I would look at is if your subclass also inherits all the `events` of the `GridLayout`. If not then your subclass might miss the mechanism to handle the addition of components to it (as it seem to happen on your other linked question). – Hoki Nov 08 '19 at 17:47
  • I have added some more information to my question, but I don't know if this helps. Everything looks like expected. – Patrick Happel Nov 11 '19 at 09:47
  • I would follow the creation of the `gridlayout` and the addition of a child object with the debugger in both the original and your custom class ... and try to see where it diverges. When following the original class, try to find out at which point the grid layout is rendered on screen, then compare to your class to see why this doesn't happen. – Hoki Nov 11 '19 at 10:58
  • I have done this, at least to a certain depth. I don't see any differences, but I will research this further. I have filed this to Matlab staff, too. It looks like a bug to me, or at least some missing documentation. – Patrick Happel Nov 11 '19 at 20:10
  • Just a thought and untested: The GridLayout class has a protected method for `handleChildAdded`, which is inherited by your subclass and is fine except that the method invokes a number of private methods, e.g. `addChildLayoutPropChangedListener`, which are not inherited by your subclass. It may be that you need to make an explicit invocation of the GridLayout methods (see [here](https://www.mathworks.com/help/matlab/matlab_oop/method-invocation.html#bup3_yj-1)) which make calls to private methods. That is, redefine the protected methods and use their superclass invocation (@). – Khlick Jul 17 '20 at 15:36

0 Answers0