java - Vaadin 基本布局 : fixed header and footer + scrollable content

标签 java layout header vaadin footer

我是 Vaadin 的新手,想知道它是否可以满足我的 Web 应用程序项目迁移需求。 实际上,我已经在一个简单的目标上浪费了时间:拥有一个具有固定页眉和页脚以及中间可滚动内容的布局。 我做了一个非常基本的摆弄我想要的东西: jsfiddle

这是我想出的主要 Vaadin 类:

public class MyVaadinUI extends UI {

// attributes

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class, widgetset = "testvaadin.aep.com.AppWidgetSet")
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {

    buildMainLayout();
}

private void buildMainLayout() {

    final VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();

    //HEADER
    final VerticalLayout headerLayout = new VerticalLayout();
    final Resource res = new ThemeResource("img/logo.png");
    final Image image = new Image(null, res);
    headerLayout.addComponent(image);

    //CONTENT
    final VerticalLayout contentLayout = new VerticalLayout();
    for(int i=0; i<80; i++){
        contentLayout.addComponent(new Button("TEST " + i));
    }

    //FOOTER
    final VerticalLayout footerLayout = new VerticalLayout();
    footerLayout.addComponent(new Label("--------------------------- footer --------------------------"));

    mainLayout.addComponent(headerLayout);
    mainLayout.addComponent(contentLayout);
    mainLayout.addComponent(footerLayout);
    mainLayout.setExpandRatio(contentLayout, 1);
    setContent(mainLayout);
}

}

启动时显示的页面正常,但是当我向下滚动时,页脚也会滚动(不是固定的)。

启动时: startup

滚动时:

scrolled down

我浏览了很多关于这个主题的页面,但我从未看到任何正确的答案。这在 Vaadin 中似乎相当复杂,尽管在 HTML 中非常简单; Vaadin 可能不适合我的需求。 不管怎样,你知道我怎样才能实现这种行为吗? 谢谢!

最佳答案

您可以使用Panel创建可滚动的中心内容区域。请参阅下面的示例。

要使面板正常工作,组件层次结构中的所有内容都必须是 setSizeFull (或等效项),而面板的内容则不能(在示例中 mainLayoutcontentPanel 为 100%,但 contentLayout 不是(隐式))

@Grapes([
        @Grab('org.vaadin.spring:spring-boot-vaadin:0.0.3'),
        @Grab('com.vaadin:vaadin-client-compiled:7.4.0.beta1'),
        @Grab('com.vaadin:vaadin-themes:7.4.0.beta1'),
       ])
import com.vaadin.ui.*

@org.vaadin.spring.VaadinUI
class MyUI extends UI {

    protected void init(com.vaadin.server.VaadinRequest request) {
        final headerLayout = new VerticalLayout(new Label('HEADER'))
        final footerLayout = new VerticalLayout(new Label('FOOTER'))

        final contentLayout = new VerticalLayout()
        80.times{ contentLayout.addComponent(new Button("TEST $it")) }
        // XXX: place the center layout into a panel, which allows scrollbars
        final contentPanel = new Panel(contentLayout)
        contentPanel.setSizeFull()

        // XXX: add the panel instead of the layout
        final mainLayout = new VerticalLayout(headerLayout, contentPanel, footerLayout)
        mainLayout.setSizeFull()
        mainLayout.setExpandRatio(contentPanel, 1)
        setContent(mainLayout)
    }

}

(与 spring run vaadin.groovy 独立运行)

关于java - Vaadin 基本布局 : fixed header and footer + scrollable content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27940668/

相关文章:

java - 单击主页/后退按钮时的 android 进度条

java - 继承 : Unexpected Output from return statement

java:Runnable和Thread接口(interface)的关系

java - 将空布局与卡片布局相结合 [java]

html - 使按钮在背景图像上居中

javascript - JS/HTML5 WebSocket : Connect without HTTP call

security - 如何从响应 header 中隐藏或删除 "X-ATG-Version"?

java - JOptionPane背景颜色

jquery - HTML5 桌面/移动博客 - jQuery UI 还是 jQuery Mobile?

c++ - C++ header 中外部变量的 undefined reference