如何动态调整GridLayout行高?

时间:2014-12-29 11:22:21

标签: java vaadin grid-layout

我正在使用Vaadin,我在给定的GridLayout中有一组数据。

内部网格我有标签作为关键和价值:

enter image description here

要求是:

enter image description here

情况是,现在值,即标签可以有更长的文本,我可以包装文本但我也想相应地动态增加该特定行高。如何使用GridLayout完成?我试过setRowExpandRatio()但没有帮助。

2 个答案:

答案 0 :(得分:0)

为了克服这种情况,我选择了CustomLayout和html模板。通过这种方式,我可以很容易地控制我的网格或其他字表 mylayout.html (VAADIN / themes / mythemes / layouts)

<table class="tg">
   <tr>
     <td class="tg-031e tg-0ord">Key1</td>
     <td class="tg-031e" location="Key1_value"></td>
     <td class="tg-031e tg-0ord">Key2</td>
     <td class="tg-031e" location="Key2_value"></td>
     <td class="tg-031e" colspan="2" rowspan="9" location="image_value" style="width: 245px;">  
       <img src="" />  
     </td>
   </tr>  
   <tr> ... </tr>  
</table>  

然后在我的代码中,我按照以下方式使用它:

CustomLayout customLayout = new CustomLayout("mylayout");  
customLayout.addComponent(new Label("Key1_value"), "Key1_value");  

等等。
我发现这个解决方案比较优雅和干净。如果可以通过其他方式实现,请让我们都知道。感谢

答案 1 :(得分:0)

GridLayout有一个addComponent方法来创建&#34;单元格&#34;跨越多个列/行。

   public void addComponent(Component component,
                         int column1,
                         int row1,
                         int column2,
                         int row2)
                  throws GridLayout.OverlapsException,
                         GridLayout.OutOfBoundsException
     

将组件添加到指定区域中的网格。   通过指定左上角(column1,row1)来定义区域   和该区域的右下角(第2列,第2行)。   坐标从零开始。

     

如果该区域已与任何现有组件重叠   出现在网格中,操作将失败并且   抛出GridLayout.OverlapsException。