Centering a Button on a HLayout

How do I get a Button to sit on the center horizontal axis of a HLayout?

This code doesn’t work on SGWT 1.1

The button is placed on the left.

package jl.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.layout.HLayout;

/**

  • Entry point classes define <code>onModuleLoad()</code>.
    */
    public class ButtonCenteringOnHLayout implements EntryPoint {

    public void onModuleLoad() {
    HLayout buttonLayout = new HLayout();
    buttonLayout.setAlign(Alignment.CENTER);
    buttonLayout.setWidth100();
    buttonLayout.setBorder(“solid black”); // debug

     final Button buttonDetail = new Button("CenterLeft");
     buttonDetail.setLayoutAlign(Alignment.CENTER);
     
     buttonLayout.addChild(buttonDetail);
     
     RootPanel.get().add(buttonLayout);
    

    }
    }

See the docs for layoutAlign, it affects the other axis. Use LayoutSpacers on either side of the button to center it on the length axis.

Simply adding LayoutSpacer’s does the trick.

But then what is the purpose of
setLayoutAlign()
or
setDefaultLayoutAlign()?
They seem redundant.

For a trwisted example by adding the spacers I get centering.
However, if I then set all the layouts to point left this has no impact on the layout (see below).

So under what circumstances are the above api’s useful?

I find this rather confusing.

public void onModuleLoad() {
	HLayout buttonLayout = new HLayout();
	buttonLayout.setAlign(Alignment.LEFT);
	buttonLayout.setWidth100();
	buttonLayout.setBorder("solid 5px");
	buttonLayout.setDefaultLayoutAlign(Alignment.LEFT);

	
	final Button buttonDetail = new Button("CenterLeft");
	buttonDetail.setLayoutAlign(Alignment.LEFT);
	buttonDetail.setBorder("solid red");
	
	buttonLayout.setChildren(new LayoutSpacer(), buttonDetail, new LayoutSpacer());
	
	RootPanel.get().add(buttonLayout);

}

None are redundant.

layoutAlign - set on a member, alignment of a particular member, on the breadth axis
defaultLayoutAlign - set on a layout, provides default for member.layoutAlign
layout.align - alignment of all members on the length axis