Vaadin:布局中的中心组件不能与setSizeFull一起使用静态值吗?

时间:2015-05-09 02:04:41

标签: java vaadin

我在布局中有一个面板,并尝试将其置于中间位置:

  1. 如果布局为100%X 100%(setSizeFull),则不起作用。面板位于窗口的左上角。
  2. 但是,

    1. 如果我设置静态值setWidht(“500px”),则面板位于500px的中心。
    2. 为什么或如何使用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
      

2 个答案:

答案 0 :(得分:1)

您已在Panel中添加了layout,并且您已拨打layout.setSizeFull()

您可以使用#setComponentAlignment这个,

VerticalLayout layout = new VerticalLayout();//For example
layout.setSizeFull()
layout.addComponent(panel);//Your panel
layout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);

<强> 修改

我认为您尚未在setSizeFull()课程上致电MainUI。您已在setSizeFull上添加了LogIn。您应该修正LogIn的高度和宽度并将this.setSizeFull()添加到MainUI

答案 1 :(得分:0)

我找到了解决方案。根据{{​​3}}&#34;未定义大小的布局不能包含具有相对大小的组件。&#34;因此,向UI添加setSizeFull:

class MyVaadinUI 
   init method 
       this.setSizeFull();
       setContent(new Login());