如何在PrimeFaces中更改面板网格的列宽

时间:2013-05-27 15:48:16

标签: jsf primefaces

我正在使用Java EE和PrimeFaces。如何在PrimeFaces中更改面板网格的列宽? 有一个例子吗?

3 个答案:

答案 0 :(得分:27)

您可以使用columnClasses在panelGrid中限定列。以下代码设置不同的宽度,并将单元格内容与顶部对齐。

<h:panelGrid columns="2" style="width: 100%" columnClasses="forty-percent top-alignment, sixty-percent top-alignment">
.forty-percent {
     width: 40%;
}

.sixty-percent {
     width: 60%;
}

.top-alignment {
     vertical-align: top;
}

答案 1 :(得分:9)

我有类似的问题,这是我的解决方案:

<p:panelGrid style="width:100%"> # notice that I do not define columns attribute in p:panelGrid!!
    <f:facet name="header"> # header
        <p:row> # p:row and p:column are obligatory to use since we do not define columns attribute!
            <p:column colspan="2"> # here I use colspan=2, coz I have 2 columns in the body
                Title
            </p:column>
        </p:row>
    </f:facet>

    <p:row>
        <p:column style="width:150px"> # define width of a column
            Column 1 content
        </p:column>
        <p:column> # column 2 will fill the rest of the space
            Column 2 content
        </p:column>
    </p:row>

    <f:facet name="footer"> # similar as header
        <p:row>
            <p:column colspan="2">
                Footer content
            </p:column>
        </p:row>
    </f:facet>
</p:panelGrid>

正如您所看到的,主要区别在于 p:panelGrid 定义属性。在页眉和页脚中,您必须使用 p:row p:column ,在我的情况下,我还必须使用colspan = 2,因为在正文中我们有2列。

希望这会有所帮助;)

答案 2 :(得分:7)

您是否考虑过样式属性? 示例:

<p:panelGrid columns="2" style="width: 50px">

否则,对于列:

<p:column style="width:50px">

请参阅此主题:how can I adjust width of <p:column> in <p:panelGrid>?

相关问题