Cannot add component to specific location in container with Table Layout

43 views
Skip to first unread message

CS

unread,
Feb 28, 2014, 2:31:01 AM2/28/14
to codenameone...@googlegroups.com
Dear CNO team!

I have a container with "Table Layout" (setup through designer) and some components inside. If I call addComponent(idx, new Component()) inside the beforeForm() method. The Component is always shown in last location and not in "idx"-th. The same thing happens if I call replace(oldComopnent, new Component(), null) method. The oldComponent is removed, but the new Component is shown in last location. This happens in simulator and Android (I did not test others).

But if I change container layout to "Grid Layout" (changed through designer) everything works as expected. Is there anything special one has to do in case of "Table Layout"?

Regards. 

Shai Almog

unread,
Feb 28, 2014, 3:17:42 AM2/28/14
to codenameone...@googlegroups.com, computer.s...@gmail.com
Hi,
table layout is a constraint based layout like BorderLayout, GridBagLayout & GroupLayout.
Constraints determine the physical position and not index, they also determine spanning etc.

E.g. from the Kitchen Sink layouts demo:
                borderLayout.setVisible(true);
                tableLayout
.setVisible(true);
               
TableLayout tl = new TableLayout(2, 4);
                layouts
.setLayout(tl);

               
// need to re-add the components since the layout requires a contraint
                layouts
.removeAll();
                layouts
.addComponent(borderLayout);
                layouts
.addComponent(boxYLayout);
                layouts
.addComponent(boxXLayout);
                layouts
.addComponent(flowLayout);
               
               
TableLayout.Constraint c = tl.createConstraint();
                c
.setHorizontalSpan(2);
                layouts
.addComponent(c, flowCenterLayout);
                layouts
.addComponent(gridLayout);
                layouts
.addComponent(tableLayout);



computer.s...@gmail.com

unread,
Feb 28, 2014, 3:42:10 PM2/28/14
to codenameone...@googlegroups.com
Thx that solved it.
Reply all
Reply to author
Forward
0 new messages