Key*_*han 1 java vaadin vaadin7
尝试在HorizontalLayout中设置按钮时,该按钮倾向于与布局中其他组件的标题部分而不是组件本身对齐。例如
HorizontalLayout hl = new HorizontalLayout();
h1.addComponent(new TextField("Test");
h1.addComponent(new Button("Do Something");
Run Code Online (Sandbox Code Playgroud)
将导致按钮与文本字段不对齐,但与标题文本对齐。
如何修复对齐方式,使其与“文本字段”对齐?
该HorizontalLayout有setComponentAlignment你可以使用这个()方法。
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);
Run Code Online (Sandbox Code Playgroud)
也许您需要另一种对齐方式,具体取决于您希望如何在HorizontalLayout中对齐组件