PDA

View Full Version : [CLOSED] TableLayout does size correctly



baluba
24 Apr 2008, 2:12 AM
Hi,

The following self-contained example code shows that panels that are added to a container which has a TableLayout are not layed out properly.
The left and right contentpanel in the code below are sized properly in reference to eachother, but they do not fill up the parent main container.




public class TableLayoutProblem implements EntryPoint {

public void onModuleLoad() {
final Viewport viewport = new Viewport();
viewport.setLayout(new FillLayout(20));
viewport.setBorders(true);

// create a container with table layout, two columns, one row
Container main = new Container();
main.setBorders(true);
TableRowLayout tableLayout = new TableRowLayout();
tableLayout.width = "100%";
main.setLayout(new TableRowLayout());

final ContentPanel left = new ContentPanel();
left.setWidth("100%"); // no effect
left.border = true;
// left.setLayout(new FillLayout());
TableData leftLayoutData = new TableData(Style.HorizontalAlignment.CENTER, Style.VerticalAlignment.MIDDLE);
leftLayoutData.width = "30%";
main.add(left, leftLayoutData);


final ContentPanel right = new ContentPanel();
right.setWidth("100%"); // no effect
right.border = true;
// right.setLayout(new FillLayout());
TableData rightLayoutData = new TableData(Style.HorizontalAlignment.RIGHT, Style.VerticalAlignment.MIDDLE);
rightLayoutData.width = "70%";
main.add(right, rightLayoutData);

viewport.add(main);
viewport.layout(true);
RootPanel.get().add(viewport);
DeferredCommand.addCommand(new Command() {
public void execute() {
left.layout(true);
right.layout(true);
viewport.layout(true);
}
});
}
}

darrellmeyer
29 Apr 2008, 8:05 PM
Try this code with beta2:

public void onModuleLoad() {
Viewport viewport = new Viewport();

TableRowLayout layout = new TableRowLayout();
layout.width = "100%"; // sets the width of the table element
layout.cellSpacing = 2;
viewport.setLayout(layout);
viewport.setBorders(true);

ContentPanel left = new ContentPanel();
left.setBorder(true);
TableData leftLayoutData = new TableData(HorizontalAlignment.CENTER, VerticalAlignment.MIDDLE);
leftLayoutData.width = "30%";
viewport.add(left, leftLayoutData);


ContentPanel right = new ContentPanel();
right.setBorder(true);

TableData rightLayoutData = new TableData(HorizontalAlignment.RIGHT, VerticalAlignment.MIDDLE);
rightLayoutData.width = "70%";
viewport.add(right, rightLayoutData);

RootPanel.get().add(viewport);
}

baluba
30 Apr 2008, 2:41 AM
Works ok! Thank you.