Question

[Flextable1][Flextable2]
[Flextable3][Flextable4]

Inside every flextable: put vertical panel

inside every verticalpanel: consists of label and link shown as diagram below:

enter image description here

I want to use for loop in the flextable but i don't know where to start first.
Please help me to solve. Thanks.

Was it helpful?

Solution

It's a very simple code. Read inline comments for more info.

// root flex table that contains other widgets
FlexTable rootFlexTable = new FlexTable();

int counter = 0;
// 2 rows and 2 columns (change it as per your requirement)
for (int i = 0; i < 2; i++) { // rows
    for (int j = 0; j < 2; j++) {// columns
        counter++;

        FlexTable flexTable = new FlexTable();
        VerticalPanel verticalPanel = new VerticalPanel();

        Label label = new Label("No " + counter + "(label)");
        Hyperlink hyperlink = new Hyperlink("Name " + counter + "(link)", 
                                                           "link" + counter);

        verticalPanel.add(label);
        verticalPanel.add(hyperlink);

        // why are you using one extra flex table 
        // that contains only single component?
        flexTable.setWidget(0, 0, verticalPanel);

        // add inner flex table at row i and column j
        rootFlexTable.setWidget(i, j, flexTable);
    }
}

RootPanel.get().add(rootFlexTable);

Screenshot:

enter image description here

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