Another HLayout + Align Question

Hi there,

I’m trying to display three different section of a header; something aligned to the left, something centred in the middle and then something aligned to the right.

Example code is as follows:

Layout header = new HLayout();
header.setWidth100();

Layout leftContainer = new HLayout();
leftContainer.setWidth("25%");
leftContainer.addMember(new Button("Left"));

Layout centreContainer = new HLayout();
centreContainer.setWidth("*");
centreContainer.setLayoutAlign(Alignment.CENTER);
centreContainer.addMember(new Button("Centre"));

Layout rightContainer = new HLayout();
rightContainer.setWidth("25%");
rightContainer.setLayoutAlign(Alignment.RIGHT);
rightContainer.addMember(new Button("Right"));

header.addMember(leftContainer);
header.addMember(centreContainer);
header.addMember(rightContainer);

Unfortunately, the button in centreContainer is not centred and the button in rightContainer is not aligned to the right.

I’ve read posts about placing VLayouts around the HLayouts but that didn’t seem to work.

My questions are:

  1. Am I going about this the right way… to have three sections in a header type layout should I be using three child layouts (or is this overkill)
  2. Is there an obvious reason why the setLayoutAlign isn’t aligning the child components as instructed? I’ve also tried setDefaultLayoutAlign with no success.

Thanks in advance! :slight_smile:

Damian

layoutAlign affects the breadth axis (width on a VLayout, height on an HLayout). Along the length axis, use Layout.align to control the alignment of all members, or use LayoutSpacers with height/width * to create alignment with multiple members.

If this doesn’t solve your problem, for more help, post a screen capture of exactly what you want and what you’re getting.

LayoutSpacer works

LayoutSpacer worked perfectly :slight_smile:

Layout header = new HLayout();
header.setWidth100();
header.setHeight(24);

header.addMember(new Button("Left"));
header.addMember(new LayoutSpacer());
header.addMember(new Button("Center"));
header.addMember(new LayoutSpacer());
header.addMember(new Button("Right"));

Thank you!

Damian