gpt4 book ai didi

css - 如何对齐/移动 Vaadin 按钮

转载 作者:太空宇宙 更新时间:2023-11-04 02:08:04 25 4
gpt4 key购买 nike

我正在学习 Vaadin,我想将两个按钮移动到弹出窗口的底部,按钮之间留有间距。我很确定我必须覆盖主题中的按钮 css,但如何更改 java 代码中按钮的绝对位置?

这是我的代码:一个简单的按钮,带有一个调用弹出方法(子窗口)的点击监听器。在下面的代码中,我试图将是按钮移动到弹出窗口的底部。

protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();

Button helloButton = new Button("Click Me");
helloButton.addClickListener(e -> helloPopUp());

layout.setMargin(true);
layout.setSpacing(true);
layout.addComponents(helloButton);
setContent(layout);
}

private void helloPopUp() {
Window subWindow = new Window("Pop Up");
HorizontalLayout subContent = new HorizontalLayout();
AbsoluteLayout layout2 = new AbsoluteLayout();
subContent.setMargin(true);

Label text = new Label( "Hello Pop Up" , ContentMode.PREFORMATTED);
subContent.addComponent(text);

Button yes = new Button("Yes");
Button no = new Button("No");
layout2.addComponent(yes, "left: 50px; bottom: 0px;");

subContent.addComponents(layout2);
subContent.addComponent(no);
subWindow.setContent(subContent);
UI.getCurrent().addWindow(subWindow);
}

最佳答案

这里有一个不使用 AbsoluteLayout 的方法

private void helloPopUp() {
Window subWindow = new Window("Pop Up");
VerticalLayout subContent = new VerticalLayout();
subContent.setMargin(true);

Label text = new Label( "Hello Pop Up" , ContentMode.PREFORMATTED);
subContent.addComponent(text);

Button yes = new Button("Yes");
Button no = new Button("No");

HorizontalLayout buttonsLayout = new HorizontalLayout();
buttonsLayout.addComponents(yes, no);
buttonsLayout.setSpacing(true);

subContent.addComponent(buttonsLayout);
subContent.setComponentAlignment(buttonsLayout, Alignment.BOTTOM_LEFT);
subWindow.setContent(subContent);
UI.getCurrent().addWindow(subWindow);
}

关于css - 如何对齐/移动 Vaadin 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40323826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com