PDA

View Full Version : [CLOSED] Can't use BorderLayout in Window Subclass



sean.mcrae
11 Sep 2008, 12:30 PM
I am subclassing Window and I get an error with the following code:



import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Element;

public class MyEntryPoint implements EntryPoint {

/* (non-Javadoc)
* @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
*/
/** {@inheritDoc} */
public void onModuleLoad() {

Dialog2 dlg2 = new Dialog2();
dlg2.show();

}

private class Dialog2 extends Window {
private LayoutContainer mainPanel;
public Dialog2() {
super();
addText("FOO!");
mainPanel = new LayoutContainer();
add(mainPanel);
}

protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
mainPanel.setLayout(new BorderLayout());
}
}
}
If I don't set the layout for the LayoutContainer then everything works fine.

sean.mcrae
12 Sep 2008, 6:20 AM
Got this running through hosted mode...

Get this stack trace:


java.lang.RuntimeException: A component in the CENTER region is required.
at com.extjs.gxt.ui.client.widget.layout.BorderLayout.onLayout(BorderLayout.java:139)
at com.extjs.gxt.ui.client.widget.Layout.layout(Layout.java:69)
at com.extjs.gxt.ui.client.widget.Container.doLayout(Container.java:251)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:338)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:236)
at com.extjs.gxt.ui.client.widget.Container.onAttach(Container.java:345)
at com.extjs.gxt.ui.client.widget.ComponentHelper.doAttach(ComponentHelper.java:20)
at com.extjs.gxt.ui.client.widget.Container.doLayout(Container.java:255)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:338)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:236)
at com.extjs.gxt.ui.client.widget.Container.onAttach(Container.java:345)
at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:231)
at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:119)
at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:86)
at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:80)
at com.extjs.gxt.ui.client.widget.Window.show(Window.java:717)
....
Is it really a requirement that the center region have a component explicitly added? Is that documented somewhere?

sean.mcrae
12 Sep 2008, 7:19 AM
Is that documented somewhere?

Yes...it is documented...sorry about that.:">

Not a bug, apparently a hardware issue: There's a nut loose behind my keyboard. :D

sean.mcrae
12 Sep 2008, 9:54 AM
So just to prove things out I tried a couple of different things. I added two different components and in one case the code works, but in another it fails. Why is this?

Replacing the onRender method originally posted withe these...

...fails...


protected void onRender(Element parent, int pos) {
mainPanel.setLayout(new BorderLayout());
Button button = new Button("DON'T PANIC!");
button.setVisible(true);
mainPanel.add(button, new BorderLayoutData(Style.LayoutRegion.CENTER));
super.onRender(parent, pos);
}



...works...


protected void onRender(Element parent, int pos) {
mainPanel.setLayout(new BorderLayout());
Hidden hid = new Hidden("DON'T PANIC!");
mainPanel.add(hid, new BorderLayoutData(Style.LayoutRegion.CENTER));
super.onRender(parent, pos);
}


Aren't both Hidden and Button (GXT's not GWT's) components?

darrellmeyer
18 Sep 2008, 8:45 PM
In most cases you do not need to override onRender. If you do, the super class should usually be first if you are not setting the components element directly.