PDA

View Full Version : tabitem layout


ttbgwt
05-30-2008, 02:09 PM
I'm having a hard time laying out widgets in a tabitem. Can you provide a snippet of code that will show how to add 3 textfield widgets to a tabitem panel, so that each widget will be equally spaced across the width of the tabitem? Sorta like each widget will be in its own column, and the three columns will take up 100% of the tab items width? I'm unsure as to add a LayoutContainer inside the tabitem, and then the widgets inside of the layout container?

darrellmeyer
06-03-2008, 07:55 AM
Here you go:

public void onModuleLoad() {
Viewport v = new Viewport();
v.setLayout(new FitLayout());

TabPanel tabs = new TabPanel();

TabItem item = new TabItem("Form Test");

FormPanel panel = new FormPanel();
panel.setHeaderVisible(false);
panel.setLayout(new ColumnLayout());

LayoutContainer left = new LayoutContainer();
left.setData(new ColumnData(.33));
left.setLayout(new FormLayout(LabelAlign.TOP));

TextField text = new TextField();
text.setFieldLabel("Left");
text.setData("anchorSpec", "-20");
left.add(text);

LayoutContainer middle = new LayoutContainer();
middle.setData(new ColumnData(.33));
middle.setLayout(new FormLayout(LabelAlign.TOP));

text = new TextField();
text.setFieldLabel("Middle");
text.setData("anchorSpec", "-20");
middle.add(text);

LayoutContainer right = new LayoutContainer();
right.setData(new ColumnData(.33));
right.setLayout(new FormLayout(LabelAlign.TOP));

text = new TextField();
text.setFieldLabel("Right");
text.setData("anchorSpec", "-20");
right.add(text);

panel.add(left);
panel.add(middle);
panel.add(right);

item.add(panel);

tabs.add(item);

v.add(tabs);

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

gr8dogs
07-29-2008, 10:56 AM
I too was trying to understand how the layout is put together, so I tried the sample code provided in response to another's question. Apparently the "setData" method is now deprecated as the code now throws an IllegalArgumentException with the suggestion to use setLayoutData instead, but it's not intuitively obvious what the correct arguments should be. (Thanks.)