Overlapping Components

The sectionHeader Canvas and the DynamicForm render on top of eachother. I looked in FireBug and it appears that they are absolutely positioned that way.

Maybe I’m doing something stupid?

public class Application implements EntryPoint {
	
    public void onModuleLoad() {
    	
        TabSet tabSet = new TabSet();
        tabSet.setWidth(700);
        tabSet.setHeight(400);

        Tab smartTab1 = new Tab("Tab One");
        Canvas tabPane1 = new Canvas();
        
        Canvas sectionHeader = new Canvas();
        sectionHeader.setContents("<span class='sectionhead'>My Section Header</span><hr />");
        tabPane1.addChild(sectionHeader);
        
        final DynamicForm form = new DynamicForm();
        form.setWidth(650);
    	
        SelectItem selectItem = new SelectItem();
        selectItem.setTitle("Country");
        LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
        valueMap.put("US", "<b>United States</b>");
        valueMap.put("CH", "China");
        valueMap.put("JA", "<b>Japan</b>");
        valueMap.put("IN", "India");
        selectItem.setValueMap(valueMap);
        
        SelectItem selectItem2 = new SelectItem();
        selectItem2.setTitle("Color");
        selectItem2.setValueMap("<span style='color:#FF0000;'>Red</span>",
                "<span style='color:#00FF00;'>Green</span>",
                "<span style='color:#0000FF;'>Blue</span>");
        
        form.setItems(selectItem, selectItem2);
        tabPane1.addChild(form);
        
        smartTab1.setPane(tabPane1);
        tabSet.setTabs(smartTab1);
        tabSet.draw();
    } 
}

Children of a Canvas use absolute positioning. To stack components and/or make them fill space, look at H/VStack and H/VLayout.

I understand, thanks!

I’m evaluating switching from ExtJS and while the two frameworks work very differently I have to say the support here is incredible.

For anyone who finds this thread having a similar issue, instead of Canvas use VStack.addMember(). VStack.addChild() results in absolute positioning, so don’t use that.

Q: With Canvas apparently the default height is 100px. I’d much prefer it to act like a normal div, ie I want the Canvas to be only as big as it has to be to hold its contents. Is this achievable?

Thanks,

Scoob

For some use cases you want to use VStack.addChild(), typically alongside addMember(). Members are stacked, children are placed manually and can serve other roles (like a drop indicator during drag and drop).

Yes, to have a Canvas be only as tall as it’s contents, just set height 1. Height acts like a minimum when overflow is “visible” (the default for Canvas).

Consider also a Label with setAutoFit(true).