Can't stack custom component in grid layout

16 views
Skip to first unread message

Gareth Murfin

unread,
Oct 4, 2019, 12:48:52 PM10/4/19
to CodenameOne Discussions
So I have a grid layout 2x2, and if I add buttons, they stack as expected. For example

myGrid.add(new Button("AAA"));
myGrid.add(new Button("AAA"));
myGrid.add(new Button("AAA"));
myGrid.add(new Button("AAA"));

Adds 4 buttons which sit in each of the cells as expected.

But when I try this with my own custom component (with its own canvas) then they dont stack into each cell, they seem to paint over the top of each other.  ie if I add 4, they all sit in cell 0,0 (painting over the top of each other) which is weird, because I have done this before and it did work perfectly. But I cant work out why.. Hopefully that is explained properly, any ideas what I am doing wrong?

Gareth Murfin

unread,
Oct 4, 2019, 2:48:30 PM10/4/19
to CodenameOne Discussions
Seems to be caused by the components themselves reporting their own size as wrong.. I thought they would report the width and height of the space availale to them based on the layout theyre added to.

Shai Almog

unread,
Oct 5, 2019, 12:41:41 AM10/5/19
to CodenameOne Discussions
Grid layout asks components for their preferred size and takes the preferred size of the largest components then uses that to construct a grid. TableLayout might be more appropriate for your needs.
Reply all
Reply to author
Forward
0 new messages