PDA

View Full Version : How to constrain a window to another component



The_Jackal
18 Mar 2009, 8:01 PM
Hi,

how can I constrain an window to another component such as a ContentPanel or part of a BorderLayout?

The it seems you can do this in ExtJs (http://http://yui-ext.com/forum/showthread.php?t=48118 (http://http//yui-ext.com/forum/showthread.php?t=48118)), but I can't get it to work in GXT.

If I have a ContentPanel and a Window as follows:


ContentPanel cPanel = new ContentPanel();
cPanel.addText("Test Panel");

Window w = new Window();
w.setSize(50, 50);
w.add(new ContentPanel());
w.setConstrain(true);
I tried:

cPanel.add(w);
w.show();and:


cPanel.layout();
w.render(cPanel.getElement());
w.show();
but neither work. Any thoughts?

Regards,
The Jackal

francescoNemesi
19 Mar 2009, 4:39 AM
Component container = new Component();

window.setContainer(container.getElement());

Regards

The_Jackal
19 Mar 2009, 2:58 PM
Hi,

Sorry, but this does not work:


Component container = new Component();
window.setContainer(container.getElement());I'm using a ContentPanel as the container in a border layout. The window is not being constrained to the center area.

Here is sample code:



public void onModuleLoad()
{
ContentPanel center = new ContentPanel();
center.add(new Html("Center"));

ContentPanel west = new ContentPanel();
west.add(new Html("West"));

Viewport viewport = new Viewport();
viewport.setLayout(new BorderLayout());

BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER, 400);
centerData.setMargins(new Margins(5, 0, 5, 0));

BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 100);
westData.setSplit(true);
westData.setCollapsible(true);
westData.setMargins(new Margins(5));

viewport.add(center, centerData);
viewport.add(west, westData);

RootPanel.get().add(viewport);

Window w = new Window();
w.setSize(200, 200);
w.setConstrain(true);
w.setContainer(center.getElement());
w.show();
}

Any other thoughts?

francescoNemesi
20 Mar 2009, 1:55 AM
Hi there,

I use the code posted in my previous message and it works just fine... ContentPanel is a Component so I can't see where the problem might be...

regards

The_Jackal
20 Mar 2009, 2:25 AM
Thanks for your reply,

Do you have a working sample? Which subclass of Component did you use?

I made a simpler example that still won't limit the window to be in one container:

public void onModuleLoad()
{
ContentPanel center = new ContentPanel();
center.add(new Html("Center"));
center.setSize(400, 400);

ContentPanel west = new ContentPanel();
west.add(new Html("West"));
west.setSize(100, 400);

HorizontalPanel main = new HorizontalPanel();
main.add(west);
main.add(center);

Window w = new Window();
w.setSize(200, 200);
w.setConstrain(true);
w.setContainer(center.getElement());
w.show();
}

Note that I also tried making center a HTMLContainer.

Cheers,
The Jackal