0

I want to create table and add a widgets to the table.

My requirement to add widgets in the table with exactly three column and the number of widgets is dynamic

For example,

MyGrid myGrid = new MyGrid( 3 ); // Three Columns

//first row
myGrid.add( new Label("row1 column1"));
myGrid.add( new Label("row1 column2"));
myGrid.add( new Label("row1 column3"));

// second row
myGrid.add( new Label("row2 column1"));
myGrid.add( new Label("row2 column2"));

How can i achieve this without using any index calculation in my code?

schoolcoder
  • 1,546
  • 3
  • 15
  • 31

1 Answers1

0

I would use a FlowPanel and do the style with css for the case with a static column count.

If the column size should be set dynamically then it a bit more tricky with a flow panel, but with some width calculation it should be possible as well.

  • Yes! It will work.. But still padding for the first and last widget of each row will differ ( which we need to manually work on to solve it) . To avoid this, I am checking if there are GWT apis already available. – schoolcoder May 20 '15 at 14:07
  • If you like to stick to a table you can use the FlexTable. Just override the add(Widget w) method. If you know the Element count it should be easy to calculate the next row column. – Andreas Basler May 21 '15 at 09:06