I have a main Window that I want to center in the middle of the page and then add components to it
........
MainWindow win = new MainWindow(); // MainWIndow extends Window
VerticalLayout layout = new VerticalLayout();
layout.setWidth("400");
Button button = new Button();
layout.addComponent(button);
layout.setComponentAlignment(button, Alignment.TOP_CENTER);
win.addComponent(layout);
win.center()
// win.setPositionY(100); DIDN'T WORK EITHER
// win.setPositionX(100); DIDN'T WORK EITHER
setMainWindow(win);
................
...
I have tried the above and the center method and the setPosition does not work. My window is still stuck in the top left corner. What am I doing wrong? How can I bring it in the middle? Any help? Using Vaadin 6.3.0
And if you’re going to center some non-full-size compoennt, say want to add a button or label to the window(panel) center, you’ll need to add a couple of sizers and set an expand rations:
Thanks guys for you suggestions. I can center components onto any layout. The Issue am facing is centering the main window so I can add layout to a centered window
I want this code to center the main window as in this code
main window == web browser page. So if you call
( (VerticalLayout) getContent() ).setSizeFull ();
- the working area will shrink to entire browser’s window, both horizontally and vertically.
Then, if you have, say, another layout (not 100% W/H) with your UI which you want to be displayed in the center of main window - try my example above with the sizers.
getContent() should not return NULL if you’re creating standard Vaadin’s Window. How do you create it ?
Thanks guys managed to center the window at last with this code
public class HashPayMain extends Application {
@Override
public void init() {
MainWindow main = new MainWindow();
VerticalLayout content = new VerticalLayout();
setTheme("chameleon-blue");
Content contPanel = new Content();
content.addComponent(contPanel);
content.setComponentAlignment(contPanel, Alignment.MIDDLE_CENTER);
main.setContent(content);
setMainWindow(main);
}
}