Question

I am creating a flex table dynamically with the following code.

for (int CurrentRow=1;CurrentRow<2;CurrentRow++)
                {
                    Label lblGettingName = new Label("Getting Name...");
                    View.getMainFlex().setWidget(CurrentRow, 0, lblGettingName);

                    Button btnViewDetails = new Button("View Details");
                    View.getMainFlex().setWidget(CurrentRow, 1, btnViewDetails);

                    Label lblGettingBid = new Label("Getting Bid...");
                    View.getMainFlex().setWidget(CurrentRow, 2, lblGettingBid);
                    View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 2, "BackNormalNotBold");

                    Label lblGettingBidDesription = new Label("Getting Bid Desription...");
                    lblGettingBidDesription.setStyleName("BidDesc");
                    View.getMainFlex().setWidget(CurrentRow, 3, lblGettingBidDesription);
                    View.getMainFlex().getCellFormatter().setWidth(CurrentRow, 3, "40");
                    View.getMainFlex().getFlexCellFormatter().setStylePrimaryName(CurrentRow, 3, ".BidDesc");

                    Label lblCalculating = new Label("Calculating..");

                    Label lblCalculatingTime = new Label("Calculating Time...");
                    View.getMainFlex().setWidget(CurrentRow, 4, lblCalculatingTime);
                    View.getMainFlex().getFlexCellFormatter().setStyleName(1,4, "BackNormalNotBold");

                    TextBox textBox = new TextBox();
                    View.getMainFlex().setWidget(CurrentRow+1, 3, textBox);
                    View.getMainFlex().getCellFormatter().setWidth(CurrentRow+1, 3, "40");

                    View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 0, "BackNormalNotBold");
                    View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 1, "BackNormalNotBold");
                    View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow, 2, "BackNormalNotBold");
                    View.getMainFlex().getFlexCellFormatter().setStyleName(CurrentRow+1, 3, "BackNormalNotBold");
                    View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 4, 3);
                    View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 2, 3);
                    View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 1, 3);
                    View.getMainFlex().getFlexCellFormatter().setRowSpan(CurrentRow, 0, 3);
                    View.getMainFlex().getFlexCellFormatter().setColSpan(CurrentRow+1, 3, 2);
                    View.getMainFlex().getFlexCellFormatter().setColSpan(CurrentRow, 3, 2);
                    View.getMainFlex().getFlexCellFormatter().setColSpan(CurrentRow-1, 3, 2);

                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 1, HasHorizontalAlignment.ALIGN_CENTER);
                    View.getMainFlex().getCellFormatter().setVerticalAlignment(CurrentRow, 1, HasVerticalAlignment.ALIGN_MIDDLE);
                    View.getMainFlex().getCellFormatter().setVerticalAlignment(CurrentRow, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 2, HasHorizontalAlignment.ALIGN_CENTER);
                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow+1, 3, HasHorizontalAlignment.ALIGN_CENTER);
                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 3, HasHorizontalAlignment.ALIGN_CENTER);

                    Button btnPlaceBid = new Button("Bid!");
                    View.getMainFlex().setWidget(CurrentRow+2, 3, btnPlaceBid);
                    View.getMainFlex().getCellFormatter().setWidth(CurrentRow+2, 3, "20");
                    btnPlaceBid.setSize("66px", "26px");

                    ToggleButton tglbtnAutomate = new ToggleButton("Automate");
                    View.getMainFlex().setWidget(3, 4, tglbtnAutomate);
                    View.getMainFlex().getCellFormatter().setWidth(3, 4, "20");
                    tglbtnAutomate.getDownHoveringFace().setText("TurnOFF");
                    tglbtnAutomate.getUpHoveringFace().setText("TurnON");
                    tglbtnAutomate.getDownDisabledFace().setText("Enable");
                    tglbtnAutomate.setHTML("Auto:OFF");
                    tglbtnAutomate.getUpFace().setHTML("Auto:OFF");
                    tglbtnAutomate.getDownFace().setHTML("Auto:ON");
                    tglbtnAutomate.setSize("54px", "18px");
                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow+2, 3, HasHorizontalAlignment.ALIGN_RIGHT);
                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow-1, 4, HasHorizontalAlignment.ALIGN_CENTER);
                    View.getMainFlex().getCellFormatter().setHorizontalAlignment(CurrentRow, 4, HasHorizontalAlignment.ALIGN_CENTER);
                }
                FlexTableHelper.fixRowSpan(View.getMainFlex());

When the loop executes only once, the correct layout is generated but when i try to create more than 1 row, the layout degerate

Was it helpful?

Solution

Most likely problems with flextable are caused by setRowSpan/setColSpan methods which can easily wreak havoc in layout. Instead of using those methods you can create composite widget/Html and place it in cells so Flextable will have less amount of rows/columns.

OTHER TIPS

FlexTable uses old element attributes of td like width, height, align etc. It is not yet adapted to use CSS instead even in the newest release. IE11 does no longer support <td align="..."> at all, for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top