0

我正在学习 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);           
        }
4

1 回答 1

2

这是一种不使用的方法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);
}
于 2016-11-01T18:04:39.963 回答