MenuBar Layout problem

Hi to all Vaadin Gurus and Comunity!!!

I faced with a problem with complex layout with MenuBar, HorizontalSplitPanel and tree.

I have a code:


@Override
	public void init() {
		Window mainWindow = new Window();
		setMainWindow(mainWindow);
		
		mainWindow.getContent().setSizeFull();
		final HorizontalSplitPanel horSplit = new HorizontalSplitPanel();
				
		MenuBar menubar = new MenuBar();
		//menubar.setSizeFull(); // doesn't work
		menubar.setWidth("100%"); // it's need by logic
		//menubar.setHeight(20.0F, 0); // doesn't work
		menubar.setImmediate(true);
		menubar.addItem("File", null);
				
		final Tree tree = new Tree("Hardware Inventory");
		tree.setImmediate(true);
		tree.setNullSelectionAllowed(false);
		tree.setSizeFull();

		final Object[][]
 planets = new Object[][]
{
				new Object[]{"Venus"},
				new Object[]{"Earth", "The Moon"},
				new Object[]{"The Moon", "Mars", "Phobos", "Deimos"},
		};

		for (int i=0; i<planets.length; i++) {
			String planet = (String) (planets[i]
[0]
);
			tree.addItem(planet);
			if (planets[i]
.length == 1) {
				tree.setChildrenAllowed(planet, false);
			} else {
				for (int j = 1; j < planets[i]
.length; j++) {
					String moon = (String) planets[i]
[j]
;
					tree.addItem(moon);
					tree.setParent(moon, planet);
				}
				tree.expandItemsRecursively(planet);
			}
		}
		
		horSplit.setSizeFull();
		horSplit.setSplitPosition(15);
		horSplit.addComponent(tree);
		mainWindow.addComponent(menubar);
		mainWindow.addComponent(horSplit);
	}

and as result I have menubar and a lot of empty space after it before the tree, but I need the tree right after menubar.

So the main question is: what I’m doing wrong and how to make it possible
and the second one - how to avoid unnesesary scrolls in my tree widged?

Will be glad any advices and suggestions…

PS: screen in attachment
11590.png

Hi Lemont, and welcome to the forum!

You need to set an expand ratio for the split panel, otherwise the “remaining” space from the root vertical layout is divided equally between its child components (menubar and splitpanel).

So ((VerticalLayout) mainWindow.getContent()).setExpandRatio(horSplit, 1); should do the trick.

And don’t set the tree to 100% size, I’m guessing that is causing the unnecessary scrollbars. So remove the tree.setSizeFull() line. The splitpanel will offer scrollbars when they are needed.

Thanks a lot!! Now it works fine.