2016-11-21 55 views
0

当试图在Horizo​​ntalLayout中设置按钮时,该按钮往往与布局中其他组件的标题部分对齐,而不是与组件本身对齐。例如,Horizo​​ntalLayout中的Vaadin按钮对齐

HorizontalLayout hl = new HorizontalLayout(); 
h1.addComponent(new TextField("Test"); 
h1.addComponent(new Button("Do Something"); 

将导致按钮不与文本字段一致,而是与其标题文本对齐。

如何修复对齐使其与文本字段对齐?

回答

3

HorizontalLayoutsetComponentAlignment()方法可用于此目的。

HorizontalLayout hl = new HorizontalLayout(); 
TextField tF= new TextField("Test"); 
h1.addComponent(tF); 
Button btn= new Button("Do Something"); 
h1.addComponent(btn); 
h1.setComponentAlignment(tF, Alignment.MIDDLE_CENTER); 
h1.setComponentAlignment(btn, Alignment.MIDDLE_CENTER); 

也许你需要另一种排列方式,这取决于您希望如何对齐Horizo​​ntalLayout

内部的部件