Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to fill a table with in the first column a number and in the second column certain data from a array.

So it will look like :

1 | Data1

2 | Data2

3 | Data3

What is the best way to add this data.

Usualy you do something like :

 Table table = new Table(3); 
 table.setWidth(100);           
 table.setDefaultVerticalAlignment(Element.ALIGN_TOP);           
 table.setCellsFitPage(true);            
 table.setPadding(2);            
 table.setSpacing(0);              
 for (int i = 1; i <= 6; i++) {            
 Cell cell = new Cell("Data " + i);            
 table.addCell(cell); }

Then you get something like :

Data 1 | Data 2 | Data 3

Data 4 | Data 5 | Data 6

Is there a specific way to fill selected cells or do I see it wrong.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
243 views
Welcome To Ask or Share your Answers For Others

1 Answer

Table table = new Table( 2 ); // 2 is the number of columns

table.setWidth( 100 );
table.setDefaultVerticalAlignment( Element.ALIGN_TOP ) ;
table.setCellsFitPage( true );
table.setPadding( 2 );
table.setSpacing( 0 );

for ( int i = 1 ; i <= 3 ; i++ )
{
     Cell leftCell = new Cell( i );
     Cell rightCell = new Cell( "Data " + i );

     table.addCell( leftCell );
     table.addCell( rightCell );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...