Button in application-level window takes half the height

I’ve recently started using an application-level window that has a HorizontalSplitPanel that occupies the whole window. Due to problems with the communication between this window and the main window, I decided to add a “Refresh” button to the application-level window. But as soon as I add the button (or any other component) to the window’s vertical layout, it takes up the entire top half of the window, and the HorizontalSplitPanel takes the bottom half.

Here’s my basic code:

public class AllActionsWindow extends Window {

public AllActionsWindow( Blackboard blackboard ) {
	super( title );

	setModal( false );

	layout = (VerticalLayout) getContent();
	layout.setSizeFull();
	layout.setMargin( true );
	layout.setSpacing( true );
	
	refreshButton = new Button();
	layout.addComponent( refreshButton );
	refreshButton.setHeight( 20, UNITS_PIXELS );	// This doesn't do anything
	
	horizSplit = new HorizontalSplitPanel();
	layout.addComponent( horizSplit );
	horizSplit.setSizeFull();
	horizSplit.setFirstComponent( new AllActionsTable( blackboard ) );
	horizSplit.setSecondComponent( new ActionNotesPanel( blackboard ) );
	horizSplit.setSplitPosition( 75, UNITS_PERCENTAGE );
	} );
}

}

Thanks for your help.

Denis

By default, VerticalLayout divides any extra space equally among its children. To work around this, you can set an expand ratio to the child that should take up all the extra space, e.g.:

layout.setExpandRatio(horizSplit, 1);

Thanks, Leif, that fixed the problem.

But I just wonder why it’s necessary? I haven’t had this problem on adding components to the VerticalLayout in normal sub-windows. Is it related to using an application-level window?

The root layout of the application level window typically has the height 100% to fill the available space. Thus, it has extra space to distribute.

The root layout of a subwindow might have undefined height by default, which means it sizes itself based on the content and thus there is never extra space to distribute.

The VerticalLayout itself should behave the same way regardless of what kind of window it is in. One significant difference is however that application-level windows usually have 100% height to fill the entire browser window whereas sub-windows are often just big enough to accomodate its contents. This means that the VerticalLayout inside an application window might get extra space to distribute whereas the sub-window doesn’t.