Alignment Right does not work until Analyze Layouts in Debug is clicked

Hi guys,

I have a strange behavior in a layout I build. I want two columns where I can put buttons in the left and right column. The buttons in the right column should be aligned to the right - but this did not work for some reason with Version 6.7.1 and 6.7.2 although it worked with 6.5.x and 6.6.x.

But if I run my application in debug mode and hit “Analyze Layouts” the buttons are repositioned and aligned correctly. Actually I do not put the buttons directly in the columns, they are wrapped with a HorizontalLayout which is aligned right.

Here is the code, maybe someone can tell me if I have done something wrong or if there is a bug …

public class SplitBarStructure extends CustomComponent {
	
	private static final long serialVersionUID = -2054450480957181685L;
	private VerticalLayout mainLayout;
	private HorizontalLayout splitLayout;
	private HorizontalLayout leftLayout;
	private HorizontalLayout rightLayout;
	
	/**
	 * Constructor.
	 */
	public SplitBarStructure() {
		setCompositionRoot(getMainLayout());
		setWidth("100%");
	}
	
	/**
	 * Builder for mainLayout.
	 * 
	 * @return the mainLayout
	 */
	private VerticalLayout getMainLayout() {
		if (mainLayout == null) {
			mainLayout = new VerticalLayout();
			mainLayout.setSizeUndefined();
			mainLayout.setWidth("100%");
			mainLayout.addComponent(getSplitLayout());
		}
		return mainLayout;
	}

	/**
	 * Builder for splitLayout.
	 * 
	 * @return the splitLaoyut
	 */
	private HorizontalLayout getSplitLayout() {
		if (splitLayout == null) {
			splitLayout = new HorizontalLayout();
			splitLayout.setSizeUndefined();
			splitLayout.setWidth("100%");
			splitLayout.addComponent(getLeftLayout());
			splitLayout.addComponent(getRightLayout());
			splitLayout.setComponentAlignment(getLeftLayout(), Alignment.TOP_LEFT);
			splitLayout.setComponentAlignment(getRightLayout(), Alignment.TOP_RIGHT);
		}
		return splitLayout;
	}

	/**
	 * Builder for rightLayout.
	 * 
	 * @return the rightLayout
	 */
	private HorizontalLayout getRightLayout() {
		if (rightLayout == null) {
			rightLayout = new HorizontalLayout();
			rightLayout.setSizeUndefined();
			rightLayout.setSpacing(true);
		}
		return rightLayout;
	}

	/**
	 * Builder for leftLayout.
	 * 
	 * @return the leftLayout
	 */
	private HorizontalLayout getLeftLayout() {
		if (leftLayout == null) {
			leftLayout = new HorizontalLayout();
			leftLayout.setSizeUndefined();
			leftLayout.setSpacing(true);
		}
		return leftLayout;
	}

	/**
	 * Add a component to the left group.
	 * 
	 * @param aComponent the Component
	 */
	public void addComponentLeft(Component aComponent) {
		getLeftLayout().addComponent(aComponent);
	}
	
	/**
	 * Add a component to the right group.
	 * 
	 * @param aComponent the component
	 */
	public void addComponentRight(Component aComponent) {
		getRightLayout().addComponent(aComponent);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.vaadin.ui.CustomComponent#removeComponent(com.vaadin.ui.Component)
	 */
	@Override
	public void removeComponent(Component c) {
		getLeftLayout().removeComponent(c);
		getRightLayout().removeComponent(c);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.vaadin.ui.CustomComponent#removeAllComponents()
	 */
	@Override
	public void removeAllComponents() {
		getLeftLayout().removeAllComponents();
		getRightLayout().removeAllComponents();
	}
}

And that is the way I use it:

splitBarStructure = new SplitBarStructure();
			splitBarStructure.addComponentLeft(getCancelButton());
			splitBarStructure.addComponentLeft(getParkButton());
			splitBarStructure.addComponentRight(getForwardButton());

Thank you in advance for any helpful comment :slight_smile:

Cheers,

Martin

Hi,

Your code example seems to work as expected when I test it. Could it be that your problem is higher up in the component hierachy, e.g. if the layout that you have your SplitBarStructure in is narrower so that there is no room for any space between the left and the right columns?

The fact that the layout starts to work as expected after pressing Analyze layouts does also indicate that there is a bug in Vaadin hiding somewhere.

Hello Leif,

yes, I also did not found the reason - but I found a workaround. I just strech the left container as much as possible:

splitLayout.setExpandRatio(getLeftLayout(), 1.0f);

Maybe the bug also only occurs when using IE8 in IE7 mode … I just hate this browser … :slight_smile:

Cheers,
Martin