Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.
(Answer) (Category) Java Apache Project : (Category) Element Construction Set : (Category) Examples :
Examples of creating a Html table...
----------
From: "PAUL J THOMPSON" thomppj@okstate.edu
To: "Hardy, David" dhardy@xlvision.com
Subject: Re: Table Rows and Data
Date: Tue, Jul 6, 1999, 8:01 AM


"Hardy, David" wrote:
> 
> By having to instantiate a new element for every new TD I can not
> dynamically create the table without assigning unique names to the TD.  In
> HTML all I would need to do is close the TD and start a new one.  It appears
> now that I have to have TR1 and TR2, therefore having to have some sort of
> incrementing systems for any new TR's I will have, since I can not have the
> same name or object reference.

Ok. I thinkI understand your question. The answer is that YES. You have
to create a different instance of TR for each row in a table. That is
just the way it works. If you want to do this dynamically, just stick it
in a for loop in something like follows:

/**** CODE SEGMENT ****?
int rows = 10;
int cols = 10;

Table bob = new Table;
for (int i = 0; i < rows; i++) {
  TR bobrow = new TR();
  for (int j = 0; j < cols; j++) {
    bobrow.addElement(new TD("Row " + i + ", Column " + j));
  }
  bob.addElement(bobrow);
}
/**** END CODE SEGMENT ****/

This litle segment of code creates a table with a dynamic number of rows
and columns (set by the variable rows and cols and with table cells
filled with a simple message. ("Row 1, Column 1", etc.)

I hope this helps a little.

Paul
----------
From: snagy snagy@norrellis.com
To: ECS ecs@list.working-dogs.com
Subject: Re: Table Rows and Data
Date: Tue, Jul 6, 1999, 7:52 AM


>Making any sense???

Yep, I think I understand now.  Here are a couple of examples dealing with
tables, do they address what you are wanting to do?

Table t = new Table();
for(x = 0 ; x < 10 ; x++)
{
    TR tr = new TR();
    for y = 0; y < 5; x++)
    {
        tr.addElement(new TD().addElement(y));
    }
    t.addElement(tr);
}

More practical example :

         while(rs.next())
            {
          table.addElement(new TR()
                    .addElement(new TD().addElement(new
A("./?desc="+rs.getString(7)+"&tab="+tab,rs.getString(1))))
                    .addElement(new TD().addElement(rs.getString(2)))
                    .addElement(new TD().addElement(rs.getString(3)))
                    .addElement(new TD().addElement(rs.getString(4)))
                    .addElement(new TD().addElement(rs.getString(5)))
                );
         }

-stephan
[Append to This Answer]
Previous: (Answer) Setting VAlign attributes
Next: (Answer) A couple of questions...
This document is: http://java.apache.org/faq/?file=246
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.709.
Please browse the categories below to previous answers to questions like yours. If you do not find the answer for your particular situation, ask for help on the appropriate mailing list.