在 Vaadin 中设置 GridLayout 行高 [英] Set GridLayout row height in Vaadin

查看:58
本文介绍了在 Vaadin 中设置 GridLayout 行高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常直接的问题,如果您在 Vaadin 中定义了 GridLayout,您如何设置所有/单个行的高度?例如:

Very straight forward question, if you have a GridLayout defined in Vaadin, how can you set the height of all / individual rows? E.g:

mainLayout = new GridLayout(2, 7);
mainLayout.setMargin(true);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
// Set row[s] height?

提前致谢!

推荐答案

我建议您阅读 vaadin 书中的后续章节.

它将解释如何在网格和单个行上设置 fullsize,以及单个行和列如何具有不同的间距.

It will explain how you set fullsize on grids and individual rows and how individual rows and columns can have different spacings.

书中的例子:

GridLayout grid = new GridLayout(3,2);

// Layout containing relatively sized components must have
// a defined size, here is fixed size.
grid.setWidth("600px");
grid.setHeight("200px");

// Add some content
String labels [] = {
        "Shrinking column<br/>Shrinking row",
        "Expanding column (1:)<br/>Shrinking row",
        "Expanding column (5:)<br/>Shrinking row",
        "Shrinking column<br/>Expanding row",
        "Expanding column (1:)<br/>Expanding row",
        "Expanding column (5:)<br/>Expanding row"
};
for (int i=0; i<labels.length; i++) {
    Label label = new Label(labels[i], Label.CONTENT_XHTML);
    label.setWidth(null); // Set width as undefined
    grid.addComponent(label);
}

// Set different expansion ratios for the two columns
grid.setColumnExpandRatio(1, 1);
grid.setColumnExpandRatio(2, 5);

// Set the bottom row to expand
grid.setRowExpandRatio(1, 1);

// Align and size the labels.
for (int col=0; col<grid.getColumns(); col++) {
    for (int row=0; row<grid.getRows(); row++) {
        Component c = grid.getComponent(col, row);
        grid.setComponentAlignment(c, Alignment.TOP_CENTER);

        // Make the labels high to illustrate the empty
        // horizontal space.
        if (col != 0 || row != 0)
            c.setHeight("100%");
    }
}

这篇关于在 Vaadin 中设置 GridLayout 行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆