Adding tabs programmatically

Hope this is simple. Assuming i have code that reads the files from a folder. let’s say my folder has 5 files. I would like to display the contents of those 5 files in their own separate tabs. I already know how to read the files and get the content, but i’m stuck where I need to create to dynamically create a tabsheet with a tab that will contain a table to display the results. I’m 50% sure this is in the documentation but can’t find it.
Thanks for your help.

This code creates 5 tabs with labels and group boxes inside:

public class Screen extends AbstractWindow {

    @Inject
    protected TabSheet tabSheet;

    @Inject
    protected ComponentsFactory componentsFactory;

    @Override
    public void init(Map<String, Object> params) {
        for (int i = 0; i < 5; i++) {
            Label label = componentsFactory.createComponent(Label.class);
            label.setValue("Label " + i);

            GroupBoxLayout groupBoxLayout = componentsFactory.createComponent(GroupBoxLayout.class);
            groupBoxLayout.setCaption("Group " + i);

            VBoxLayout tabContent = componentsFactory.createComponent(VBoxLayout.class);
            tabContent.setSpacing(true);
            tabContent.setMargin(true, false, true, false);

            tabContent.add(label);
            tabContent.add(groupBoxLayout);
            tabContent.expand(groupBoxLayout);

            TabSheet.Tab tab = tabSheet.addTab("tab" + i, tabContent);
            tab.setCaption("Tab " + i);
        }
    }
}

See also the sample project attached.

tabsheet.zip (13.9K)

2 Likes