View Full Version : GWT widgets' margins in RowLayout in beta 5?

12 Jun 2008, 7:54 AM
The setMargin/setSpacing was removed from RowLayout and it seems like there is no good way now to set margins for GWT components added to the RowLayout.
The setStyleAttribute (that is suggested in the JavaDoc and example) is a method of the GXT Component class so it would work if you add GXT components to the container with RowLayout but what about the cases when you need to add GWT component.
The only solution I can see is to wrap any GWT component in to the WidgetComponent is this is the right way.

12 Jun 2008, 9:10 AM
Any widget added to a container which is not a component will be wrapped automatically. You have 3 choices:

1. Wrap your widget before adding to container.
2. Add to container then get the wrapped widget.
2. Use DOM to set the margin: DOM.setStyleAttribute(widget.getElement(), "margin", "10");

12 Jun 2008, 9:11 AM
ok, thanks

12 Jun 2008, 10:50 AM
Hi Darrel,

It seems that one of the advantages GWT and Ext-GWT is the notion that java developers (or non-javascript or CSS experts) are able to program RIAs effectively. The replacement of methods such as setMargin() and setSpacing() in favor of methods that interact with the underlying CSS seem to contradict the advantage mentioned above. Certainly the workarounds suggested in this thread indicate a regression in the ease-of-use of the API.

I am curious about the reasoning and philosophy regarding this change?


12 Jun 2008, 11:35 AM
You raise some good points. The reason for the change is related to how the layouts now work. Previously, margins and spacing were manually calculated and the widgets size and position were adjusted. This has been changed in favor of using CSS. With this approach you are able to specify margins for all 4 sides and can use all CSS units, not just pixels.

I have made some changes so that you can still apply margins using the layout. First, there is a new LayoutData class that supports a Margins object. RowData, FlowData (new), FillData (new) now extends LayoutData. The base Layout class will apply the margins automatically when the component is rendered. So you can now either apply margins directly, or use a LayoutData.

For example:

public void onModuleLoad() {
Viewport v = new Viewport();
v.add(new Button("Button 1"), new FlowData(10));
v.add(new Button("Button 2"), new FlowData(0, 5, 5, 5));

How does this sound?

12 Jun 2008, 12:18 PM

me like the new layoutdata ways which is very in-the-spirit-of GWT me thinks....

12 Jun 2008, 6:15 PM
Yes, the "layout data" approach is much better and consistent with BorderLayout and RowLayout.


12 Jun 2008, 11:10 PM
It looks good =D>