screen layout issue

Hello, I have a screen that should display a GroupBoxLayout. Within that box layout, there should be a Label and a table.
My problem is that there’s a big gap between the label and the table. My question is how can I go about eliminating that gap (space)?
Here’s the code that I have.

GroupBoxLayout groupBoxLayout = componentsFactory.createComponent(GroupBoxLayout.class);
                String header = repResults.getGroupName() + "-" + repResults.getReportName() + "-" + repResults.getPortfolio();
                Label label = componentsFactory.createComponent(Label.class);

                companion.initBox(groupBoxLayout, delimiter, tabData, ignoreType, ignoreValue,false);
1 Like

GroupBoxLayout places its components vertically, like VBox. By default, each component gets a slot of equal size. To give all available space in the direction of placement to one component, expand it:


Thanks Konstantin. The problem is that my table is created in my companion method. so I changed my method to return the tableID. Then, I should be able to expand it but I get an error:
Here’s my code:

String tableID = companion.initBox(groupBoxLayout, delimiter, tabData, ignoreType, ignoreValue,false);

                Component table = groupBoxLayout.getComponent(tableID);

However, the code above generates the following error:

Caused by: java.lang.NullPointerException
	at com.haulmont.cuba.gui.components.ValuePathHelper.parse(
	at com.haulmont.cuba.gui.ComponentsHelper.getComponent(
	at com.haulmont.cuba.web.gui.components.WebGroupBox.getComponent(
	... 61 more

It seems that you return null instead of ID from your companion method.

Yes I see now that it is returning null. I think there’s something wrong in the companion method. For some reason the table ID always return null no matter what ID I set it to.
At the top of the class, I have this:
TreeTable treeTable = null;

Here’s my method:

public String initBox(GroupBoxLayout groupBoxLayout, String delimiter, String htmlData, String ignoreType, Double ignoreValue,
                        boolean differenceOnly) {"in the companion method");
        /*try {
            File compareFile = new File("htmldata.xml");
        catch (IOException e)
            log.error("could not write htmldata.xml file");
        }*/"Done printing the data");
        com.vaadin.ui.Panel panel = (com.vaadin.ui.Panel) WebComponentsHelper.unwrap(groupBoxLayout);
        ((com.vaadin.ui.Layout) panel.getContent()).removeAllComponents();

        /*if(table != null)
            ((com.vaadin.ui.Layout) panel.getContent()).removeAllComponents();

        //com.vaadin.ui.Grid grid = new com.vaadin.ui.Grid();
        treeTable = new com.vaadin.ui.TreeTable();
        treeTable.setId("ResultTable");"Created new table with ID " + treeTable.getId());
        IndexedContainer ic = new IndexedContainer();
        Document doc = Jsoup.parse(htmlData);
        htmlData = null;
        Elements tables = doc.getElementsByTag("table");
        Element htmlTable = tables.get(1);
        Elements rows = RemoveLinks(htmlTable);
        if(rows.size() < 2)
            //Create header table
            Table headerTable = new Table();
            headerTable.addContainerProperty("No records were returned",String.class,"");
            ((com.vaadin.ui.Layout) panel.getContent()).addComponent(headerTable);
            return headerTable.getId();
        int headerRowNum = GetHeaderRowPos(rows, delimiter);
        Element headerRow = rows.get(headerRowNum);
        Elements tdHeaders = headerRow.getElementsByTag("td");
        Element refHeaders = tdHeaders.get(1);
        String headers = AppendDiffColumns(refHeaders.text(),delimiter);
        String[] finalHeaders = headers.split(delimiter);

        for(int index = 0; index < finalHeaders.length; index=index+2)
            if(finalHeaders[index].equals("")) {
                finalHeaders[index] = "Header" + index;
                finalHeaders[index+1] = "Header" + index + finalHeaders[index+1];

        //Add headers to container
        Integer headerNum = 0;
        for(String p : finalHeaders)
        //Add rowclass flag header
        treeTable.addContainerProperty("class", String.class,"");

        try {
            for (int i = headerRowNum+1; i < rows.size(); i++) {
                Elements cells = rows.get(i).getElementsByTag("td");
                Element refCells = cells.get(1);
                Element compCells = cells.get(3);
                String refCellsDat = AppendDiffData(refCells.text(),delimiter);
                String compCellsDat = AppendDiffData(compCells.text(),delimiter);
                String[] refCellsData = refCellsDat.split(delimiter, -1);
                String[] compCellsData = compCellsDat.split(delimiter,-1);

                if (refCellsData.length < finalHeaders.length) {
                    //fill the ref data with blank values
                    refCellsData = new String[finalHeaders.length];
                    Arrays.fill(refCellsData, "");
                if (compCellsData.length < finalHeaders.length) {
                    //fill the ref data with blank values
                    compCellsData = new String[finalHeaders.length];
                    Arrays.fill(compCellsData, "");

                String[] refAttr = new String[]{refCells.attr("class")};
                String[] compAttr = new String[]{compCells.attr("class")};

                //Determine whether the rows are the same or if they are different
                boolean isSame = isSameRows(refCells, compCells);
                String[] arrayRef = new String[refCellsData.length + refAttr.length];
                String[] arrayComp = new String[compCellsData.length + compAttr.length];
                System.arraycopy(refCellsData, 0, arrayRef, 0, refCellsData.length);
                System.arraycopy(refAttr, 0, arrayRef, refCellsData.length, refAttr.length);

                System.arraycopy(compCellsData, 0, arrayComp, 0, compCellsData.length);
                System.arraycopy(compAttr, 0, arrayComp, compCellsData.length, compAttr.length);
                if (isSame) {
                    Object itemRefId = ic.addItem();
                    //Object itemCompId = ic.addItem();
                    if(differenceOnly == false)
                        treeTable.addItem(arrayRef, itemRefId);
                    //table.addItem(arrayComp, itemCompId);
                    //log.debug("Added:" + Arrays.deepToString(arrayRef));
                    //log.debug("Added:" + Arrays.deepToString(arrayComp));
                } else {
                    //the rows are different so we need to determine which fields are different
                    Object itemRefId = ic.addItem();
                    Object itemCompId = ic.addItem();
                    for (int j = 0; j < arrayRef.length-1; j=j+2) {
                        if (!arrayRef[j].equals(arrayComp[j])) {
                            String difference = GetDifference(arrayRef[j],arrayComp[j],ignoreType,ignoreValue);
                            if(!difference.equals("")) {
                                arrayRef[j] = "[" + arrayRef[j] + "]";
                                arrayComp[j] = "[" + arrayComp[j] + "]";
                                arrayComp[j + 1] = "[" + difference + "]";
                    treeTable.addItem(arrayRef, itemRefId);
                    treeTable.addItem(arrayComp, itemCompId);
                    treeTable.setParent(itemCompId, itemRefId);
        catch(Exception e)
            log.error("Error adding rows: " + e.getMessage());
"number of rows=" + rows.size());

        // Set cell style generator
        treeTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
            public String getStyle(Table source, Object itemId, Object propertyId) {
                if(propertyId != null ) {
                    Item item = source.getItem(itemId);
                    if(item.getItemProperty(propertyId).getValue().getClass() == String.class) {
                        String rowValue = (String) item.getItemProperty("class").getValue();
                        String cellValue = (String)item.getItemProperty(propertyId).getValue();
                        if(rowValue.equals("ch1") || rowValue.equals("del"))
                                return "yellow";
                                return "reference";
                        else if(rowValue.equals("ch2") || rowValue.equals("ins"))
                                return "yellow";
                                return "compare";
                        else {
                            return null;
                    } else {
                        return null;
                } else {
                    return null;


        //( panel.getContent()).setSizeUndefined();
        ((com.vaadin.ui.Layout) panel.getContent()).addComponent(treeTable);
        return treeTable.getId();


I see. The table is a Vaadin component, and its ID has nothing to do with CUBA component ID. Moreover, this table does not exist in the CUBA components tree, so you cannot take it from groupBoxLayout. It actually connected only to the Vaadin panel inside the GroupBox.
To solve your problem with layout, try to do it in your companion code:

((com.vaadin.ui.AbstractOrderedLayout) panel.getContent()).setExpandRatio(treeTable, 1);

Also, when I tried to find out the components that are in my GroupBoxLayout, it returns 0;

String tableID = companion.initBox(groupBoxLayout, delimiter, tabData, ignoreType, ignoreValue,false);
                Collection<Component> components = groupBoxLayout.getComponents();
                Component tableComponent = null;
                for(Component component : components)
                    if(component != null) {
                        tableComponent = component;


It worked great. Thanks Konstantin.