java - 在 Vaadin 中设置 GridLayout 行高

标签 java vaadin

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

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

提前致谢!

最佳答案

我建议您阅读following chapter in the book of vaadin .

它将解释如何在网格和各个行上设置全尺寸,以及各个行和列如何具有不同的间距。

书中的示例:

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%");
    }
}

关于java - 在 Vaadin 中设置 GridLayout 行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18350978/

相关文章:

java - Java 中数据集的规范化

java - Vaadin 和数据模型。我如何获取标签字段使用的属性数据模型实现存储的值???瓦丁

java - 右对齐文本字段中的文本 - vaadin

java - 在 Vaadin 上播放视频

java - Vaadin 提供实时图表吗?

java - 使用 DynamoDBMapper 保存具有版本化属性的新项目

java - 从带有其他字符的Java字符串中提取时间

java - 使用不同的扩展重构 else-if 运算符?

java - 为什么 Applet 的继承类没有必要重写其所有方法,因为 Applet 类是抽象类

java - Vaadin View - 导航器无法解析