Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Newbie question about Layouts/DynamicForm

    Hello,

    im new to smartgwt. I'm trying to develop a kind of recipe-manager and encountered some problems at the very first steps. When I try to add a DynamicForm to an existing layout, the content of the DynamicForm appears at absolute 0,0, not at the expected position of the Layout.

    Everything works fine when I'm setting up the complete Layout again, but replacing only a part of the layout isn't working. When I change the
    Code:
    MainArea.draw();
    inside the mouse listener into
    Code:
    vLayout.draw();
    nothing is displayed, although my vLayout is parent of "MainArea" ?!

    Need some help, see reduced coding below,


    Carsten

    Code:
    package com.carstenroesner.cookbook.client;
    
    import com.google.gwt.core.client.EntryPoint;
    
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.*;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.menu.Menu;
    import com.smartgwt.client.widgets.menu.MenuButton;
    import com.smartgwt.client.widgets.menu.MenuItem;
    import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
    
    public class Cookbook implements EntryPoint {
    
    	private Canvas MainArea = new DynamicForm();
    	private VLayout vLayout = new VLayout();
    
    	public void onModuleLoad() {
    
    		vLayout.setWidth100();
    		vLayout.setHeight100();
    		vLayout.addMember(new DummyArea("100%", "150px", "header"));
    		vLayout.addMember(this.getMenu());
    		vLayout.addMember(MainArea);
    		vLayout.addMember(new DummyArea("100%", "30px", "footer"));
    
    		vLayout.draw();
    	}
    
    	class DummyArea extends Label {
    
    		public DummyArea(String width, String height, String contents) {
    			setAlign(Alignment.CENTER);
    			setBorder("1px solid #808080");
    			setBackgroundColor("lightgray");
    			setContents(contents);
    			if (width != null)
    				setWidth(width);
    			if (height != null)
    				setHeight(height);
    		}
    	}
    
    	public HLayout getMenu() {
    
    		HLayout ReturnLayout = new HLayout();
    
    		Menu menu = new Menu();
    
    		menu.setShowShadow(true);
    		menu.setShadowDepth(10);
    
    		MenuItem addRecipe = new MenuItem("Add Recipe", "", "Ctrl+N");
    
    		com.smartgwt.client.widgets.menu.events.ClickHandler addRecipeClickHandler = new com.smartgwt.client.widgets.menu.events.ClickHandler() {
    			@Override
    			public void onClick(MenuItemClickEvent event) {
    				MainArea = erfasseRezept();
    				MainArea.draw();
    			}
    		};
    		addRecipe.addClickHandler(addRecipeClickHandler);
    
    		menu.setItems(addRecipe);
    		MenuButton m = new MenuButton("Recipes", menu);
    		ReturnLayout.addChild(m);
    		return ReturnLayout;
    	}
    
    	private DynamicForm erfasseRezept() {
    		DynamicForm form = new DynamicForm();
    
    		TextItem textItem = new TextItem();
    		textItem.setTitle("Text");
    		textItem.setHint("<nobr>A plain text field</nobr>");
    
    		LinkItem linkItem = new LinkItem("link");
    		linkItem.setTitle("LinkItem");
    		linkItem.setLinkTitle("Click Me");
    		form.setFields(textItem, linkItem);
    
    		// removing these doesn't change anything
                    form.setHeight100();
    		form.setWidth100();
    		return form;
    	}
    
    }

    #2
    Not sure exactly what your seeing, but I ran your code and got exactly what I would expect. See attached image. The form appear at 0,0 relative to the label "Header"
    Attached Files

    Comment

    Working...
    X