Vaadin:Layout 中的中心组件不能仅与静态值一起使用 setSizeFull?
Vaadin: center componet in Layout dont work with setSizeFull just with static values?
我在布局中有一个面板,并试图将其居中:
- 如果布局为 100% X 100% (setSizeFull),则不起作用。面板位于 Window.
的左上角
但是,
- 如果我分配一个静态值 setWidht("500px"),则面板位于 500px 的中心。
为什么或如何使用 setSizeFull 属性 使面板在布局中居中?
一些伪代码:
class MyVaadinUI
init method
setContent(new Login());
和
class Login extends CustomComponent // Vaadin Composite
Login() // constructor
vLayout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
// Code for VerticalLayout and panel is autogenerate by wysiwyg editor
//the problem if that if vlayout is set with 100% x 100% (setSizefull)
//the panel is place in the top-left corner BUT if a set a static value
// 1280x800 it is correct place in the middle center
您在 layout
中添加了 Panel
并且调用了 layout.setSizeFull()
.
你可以用#setComponentAlignment
这个,
VerticalLayout layout = new VerticalLayout();//For example
layout.setSizeFull()
layout.addComponent(panel);//Your panel
layout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
编辑
我想你没有在你的 MainUI
上调用 setSizeFull()
class.You 已经在 LogIn
上添加了 setSizeFull
。你应该固定高度和宽度LogIn
并将 this.setSizeFull()
添加到 MainUI
.
我找到了解决办法。根据 this "A layout with undefined size can't contain a component with relative size." 所以将 setSizeFull 添加到 UI 有效:
class MyVaadinUI
init method
this.setSizeFull();
setContent(new Login());
我在布局中有一个面板,并试图将其居中:
- 如果布局为 100% X 100% (setSizeFull),则不起作用。面板位于 Window. 的左上角
但是,
- 如果我分配一个静态值 setWidht("500px"),则面板位于 500px 的中心。
为什么或如何使用 setSizeFull 属性 使面板在布局中居中?
一些伪代码:
class MyVaadinUI
init method
setContent(new Login());
和
class Login extends CustomComponent // Vaadin Composite
Login() // constructor
vLayout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
// Code for VerticalLayout and panel is autogenerate by wysiwyg editor
//the problem if that if vlayout is set with 100% x 100% (setSizefull)
//the panel is place in the top-left corner BUT if a set a static value
// 1280x800 it is correct place in the middle center
您在 layout
中添加了 Panel
并且调用了 layout.setSizeFull()
.
你可以用#setComponentAlignment
这个,
VerticalLayout layout = new VerticalLayout();//For example
layout.setSizeFull()
layout.addComponent(panel);//Your panel
layout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
编辑
我想你没有在你的 MainUI
上调用 setSizeFull()
class.You 已经在 LogIn
上添加了 setSizeFull
。你应该固定高度和宽度LogIn
并将 this.setSizeFull()
添加到 MainUI
.
我找到了解决办法。根据 this "A layout with undefined size can't contain a component with relative size." 所以将 setSizeFull 添加到 UI 有效:
class MyVaadinUI
init method
this.setSizeFull();
setContent(new Login());