Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] Creating a new table with an existing Table
 object.

william g cummings

2007-06-14

Replies:


Hello -
I've looked through the FAQ and can't find the answer, so here we are....

What I am trying to do is place two tables on a page.  Each table has similar characteristics (ie, 6 columns wide, etc).  In order to save memory, I need to "re-use" the table object created for the first table to create the second.  To do this, I used MyTable.deleteAllRows().  However, when I go to add this second table to the document (using MyDoc.add(MyTable)) I get an error.  I get a different error if I use a loop of MyTable.deleteLastRow().  This seemed to work in 1.2.3 of iText; we've just upgraded to 2.0.4 and it stopped working.  Please see the following code snippets:

Scenario 1 (assume all cells are defined with a mix of row/column dimensions, but that it all adds up to a table 6 col wide x 8 rows deep):

MyTable = Table(6);
    <stuff to define cells>
MyTable.addCell( cell_1 );
MyTable.addCell( cell_2 );
    <etc.;  for 8 rows>
MyDoc.add( MyTable );    // OK so far....

MyTable.deleteAllRows(); // Here's the key.
  <similar addition of cells as above>
MyDoc.add( MyTable );    // Get DocumentException: java.lang.IndexOutOfBoundsException: Index: 5, Size: 5


Scenario 2:
Exactly the same as Scenario 1, except I used a while-loop instead of the deleteAllRows() method:

while (MyTable.deleteLastRow() == true) { };

// Now, begin adding cells to what I think is an empty table>
MyTable.addCEll( cell_n );    // Get java.lang.IndexOutOfBoundsException: Index: 0, Size: 0


Am I missing something?  Do you need more information?

Many Thanks,
Will Cummings


email: william.g.cummings@seagate.com

   "Nothing is as easy - nor as difficult - as it first appears"
            -- Albert Einstein.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
©2008 junlu.com - Jax Systems, LLC, U.S.A.