Layout in Popup Window

Hello,
I would like to have a Popup window, that would be parent for other windows. I’d like this window has “OK” and “Cancel” buttons on the
bottom
. Following code creates such window, but when resizing it, buttons stay on the same position and don’t move to be always on bottom.

[code]
package cz.pse.services.component;

import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.ui.AbstractComponentContainer;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

@SuppressWarnings(“serial”)
public abstract class WindowWithButtons extends Window implements ClickListener{

protected Button ok = new Button("OK");
protected Button cancel = new Button("Cancel");

private AbstractComponentContainer viewer;

public WindowWithButtons(){
	super();
	buildMainLayout();
}

public WindowWithButtons(String caption){
	this();
	setCaption(caption);
}

protected void buildMainLayout() {
	center();
	setClosable(false);
	VerticalLayout mainLayout = new VerticalLayout();
	mainLayout.setMargin(true);
	mainLayout.setSpacing(true);
	viewer = createViewer();
	mainLayout.addComponent(viewer);
	viewer.setSizeFull();
	mainLayout.setExpandRatio(viewer, 1);
	Component buttonPannel = createButtons();
	mainLayout.addComponent(buttonPannel);
	buttonPannel.setWidth("100%");

// mainLayout.setSizeFull();
setContent(mainLayout);
}

protected Component createButtons() {
	HorizontalLayout layout = new HorizontalLayout();
	layout.setSpacing(true);
	ok.addClickListener(getOKAction());
	ok.setWidth(7, Unit.EM);
	ok.setClickShortcut(KeyCode.ENTER);
	layout.addComponent(ok);
	layout.setComponentAlignment(ok, Alignment.MIDDLE_LEFT);
	cancel.addClickListener(getCancelAction());
	cancel.setWidth(7, Unit.EM);
	cancel.setClickShortcut(KeyCode.ESCAPE);
	layout.addComponent(cancel);
	layout.setComponentAlignment(cancel, Alignment.MIDDLE_RIGHT);
	return layout;
}

@Override
public void buttonClick(ClickEvent event) {
	setVisible(false);		
}

protected AbstractComponentContainer getViewer() {
	return viewer;
}

protected AbstractComponentContainer createViewer() {
	VerticalLayout mainLayout = new VerticalLayout();
	return mainLayout;
}

protected ClickListener getOKAction() {
	return this;
}

protected ClickListener getCancelAction() {
	return this;
}

protected void setOKCaption(String caption){
	ok.setCaption(caption);
}

protected void setCancelCaption(String caption){
	cancel.setCaption(caption);
}

}

[/code] When I uncomment line 44 (mainLayout.setSizeFull();), the behavior is proper, but some windows are too small on the begging and no widgets are visible on it.
How can I build the required window, to have proper size in all cases?
I’m attaching some screenshots to demonstrate the problem.
Agata
12988.png
12989.png
12990.png
12991.png

Hi Agata,

try to put your viewer to setSizeUndefined, and all your layout components to the same size (i.e. setSizeUndefined) instead of setSizeFull, this will make all your components fits to the space they need.

HTH,

Javi

For undefined size, the buttons don’t stay on the bottom: it appears empty space
under
the buttons instead of the component
above
the buttons, make bigger.

This sounds a bit similar to another current thread going on:
SubWindow with static footer and sizing-to-content

Yes, it is. But my (imperfect) solution, still looks good enough.