Scrolling tree issues

All,

I’ve been trying to create a panel with scrollbars containing a tree widget.

I’ve put my tree in a horizontalLayout in a panel of fixed size. This gives me two scroll bars. When I collapse the tree so that the horizonral scrollbar is no longer required, the tree no longer fills the panel.

How can I ensure that the tree fills the panel in both directions, even when the content is smaller than the panel?

EDIT: Far from ideal - setWidth(“Big number”) kludges it.

Code below:

public void init() { 
	
	Window main = new Window("Scrollbar test");
	setMainWindow(main);
	
	VerticalLayout root = new VerticalLayout();
	main.setContent(root);
	main.getContent().setSizeFull();
	
	HierarchicalContainer container = ExampleUtil.getEntityTreeBean();
	Tree tree = new Tree("Test",container);
	
	// EDIT - kludge
            tree.setWidth("800px");

	// Make sure tree is expanded
	for (Object id : tree.rootItemIds()) {
		tree.expandItemsRecursively(id);
	}
	
	HorizontalLayout hp = new HorizontalLayout();
	hp.addComponent(tree);
	
	Panel treePanel = new Panel();
	treePanel.setScrollable(true);
	treePanel.setContent(hp);
	treePanel.setHeight("600px");
	treePanel.setWidth("400px");
	
	root.addComponent(treePanel);
}