0

我正在创建一个 GWT 应用程序。在我所有的屏幕中,一个需求是经常性的:向屏幕添加大量组件并自动将它们组织成 2 或 3 列。我想为此创建一个模板,但在此之前,我想知道是否已经为这种需求定义了一些东西。

理想情况下,这就是我想做的:

MyLayout myLayout = new MyLayout(nbColumns);
myLayout.add(widget1);
myLayout.add(widget2);
myLayout.add(widget3);
myLayout.add(widget4);
myLayout.add(widget5);
...

并让组件自动按nbColumns列组织。

GWT 或 GXT 3 中的任何解决方案将不胜感激。如果此解决方案可与 uiBinder 一起使用,我也将不胜感激。

4

1 回答 1

0

Use TableLayout

Usage example:

public class TableForm extends ContentPanel{
      setLayout(new TableLayout(2)); // number of columns in the table
      Button button1 = new Button(); // any widget, button is just example
      Button button2 = new Button(); 
      add(button1,new TableData("100%","100%")); // width and height
      add(button2,new TableData("100%","100%")); 
}

Number in TableLayout's constructor is number of columns - layout automatically organizes your widgets in specified number of columns. You have to only perform add() operation.

Note, that usually it's better not to set height. In such case, widget's height will be default. Otherwise, it will be stretched to the specified percents.

One more advice - use setBorder(int width) (width>0) method of TableLayout to see how exactly TableLayout organized your components. Also, TableData objects has rowspan and colspan properties - you may find it useful.

于 2013-06-06T06:57:56.173 回答