Hi,
I’m struggling with a layout problem and if anyone would be willing/knows how to help out i would appreciate it. Code for a test window/panel to demo my problem is pasted below.
TestPanel - is a panel of buttons.
TestWindow - contains just a horizontal layout that TestPanel is added to
I’m basically trying to have the TestPanel middle aligned within the main horizontal layout of the TestWindow class, and if the TestWindow is resized to a point where not all the buttons fit the window then a horizontal scrollbar should appear.
When setting TestPanel to undefined size the panel is middle aligned but no scrollbar appears when the window is resized. When not setting as undefined the scrollbars do appear but the panel is not middle aligned any longer.
I’ve been trying various things with no luck, i believe it must be something simple i’m missing and/or not understanding about the layouts, so i would appreciate some input and assistance on how to get this working.
Tnx a lot
Cheers
public class TestWindow extends Window {
public TestWindow(boolean test) {
TestPanel tp = new TestPanel();
HorizontalLayout mainhl = new HorizontalLayout();
// When this line is commented out the panel is left aligned and scrollbars appear fine
// When this line is un-commented then the panel is middle aligned as required but no scrollbars appear when the window is resized
//tp.setSizeUndefined();
mainhl.setWidth("100%");
mainhl.addComponent(tp);
mainhl.setComponentAlignment(tp, Alignment.MIDDLE_CENTER);
setSizeFull();
setContent(mainhl);
}
}
public class TestPanel extends Panel {
private HorizontalLayout layout = new HorizontalLayout();
public TestPanel() {
setContent(layout);
setStyleName(Reindeer.PANEL_LIGHT);
setScrollable(true);
initTestButtons();
}
private void initTestButtons() {
Button cashSaleB = new FrontPageAction("Cash Sale");
Button cashCarryB = new FrontPageAction("Cash & Carry");
Button tenderB = new FrontPageAction("Tender");
Button clearB = new FrontPageAction("Clear");
layout.addComponent(cashSaleB);
layout.addComponent(cashCarryB);
layout.addComponent(tenderB);
layout.addComponent(clearB);
layout.setSizeUndefined();
}
}