The ElanBeans
for table has many constructors and methods to set run-time data. Table
is nothing but 2 dimensional array, and TableCB provides many simple and
flexible ways to fill the table cells. User can set any ElanBean or any
String to each cell. You will see later, the wide range of ElanBeans
available, which can build any thing you can imagine.
Here is a simple example of
ElanBean for Table component:
Name |
Address |
Occupation |
Jack |
Down Town |
Doctor |
Jill |
Lake Side |
Professor |
Bill |
High Street |
Engineer |
The code required to build this
is:
TableCB
tab = new TableCB( 4,3);
Object
vals []= {"Name","Address","Occupation","Jack","Down Town","Doctor","Jill","Lake
Side","Professor","Bill","High Street","Engineer"};
int
k=0;
for(int
I = 0; I < 4; I++) {
for(int J = 0; J < 3; J++)
tab.setCellValue( I, J, vals[k++]); //
Set each cell to an Object.
}
tab.setTableStyle("<TABLE WIDTH=\"100%\">");
// Changing the default WIDTH.
Explanation
- Create an object of TableCB
Pass the no. of rows and columns you want into the constructor of the TableCB
- Set the contents of the Table.
Define an array of type Object containing the contents of the Table
set the Contents of Table with the above array using setCellValue(int
i,int j,value[])
where integer values i and j will identify the cell
- Build the Table using buildWC(out).
this method will generate the necessary HTML code required for the above
Table.
by this
time you might have felt how simple it is,ofcourse if this is all what
ElanBean Table can do is useless.You can customize the above table in so
many ways. we
will go step by step.
Setting Table Header
To set the table Header, include
the below line any where in the above code before buildWC( ) method
tab.setTableHeader("<P><FONT COLOR=\"#3A0A76\">Member Details</FONT>");
See the Table with Header
Member
Details |
Name |
Address |
Occupation |
Jack |
Down Town |
Doctor |
Jill |
Lake Side |
Professor |
Bill |
High Street |
Engineer |
Setting Common Style to all
Cells
If you want to set the common
style for all the cells in the table use setDefCellStyle(String style),for
example
tab.setDefCellStyle("<TD
WIDTH=\"33%\" BGCOLOR=\"#FFFFCC\"><P ALIGN=\"CENTER\">");
Table
with all cells having same style
Member
Details |
Name
|
Address
|
Occupation
|
Jack
|
Down Town
|
Doctor
|
Jill
|
Lake Side
|
Professor
|
Bill
|
High Street
|
Engineer
|
Setting Column Headers
To set
Column Header style,include the following
tab.setColHdrStyle("<TD WIDTH=\"33%\" BGCOLOR=\"green\"><P ALIGN=\"CENTER\">
");
Table with Column Headers
Member
Details |
Name
|
Address
|
Occupation
|
Jack
|
Down Town
|
Doctor
|
Jill
|
Lake Side
|
Professor
|
Bill
|
High Street
|
Engineer
|
Setting Stripes
To apply
a set of colors to the rows use .setStripes( ) method
tab.setStripes(stripes)
whereString
stripes[] = { "<TD BGCOLOR=\"#A5FED8\"> ","<TD BGCOLOR=\"#A8BBFB\">
"};
Table with Stripes style
Member
Details |
Name
|
Address
|
Occupation
|
Jack |
Down
Town |
Doctor |
Jill |
Lake
Side |
Professor |
Bill |
High
Street |
Engineer |
Setting Foreground colors,Font
Styles,Sizes etc.,
You can set the Foreground
color,font size,font face of the table headers,column headers and for all
text using TextCB object.
for example,to set the Table
Header by using TextCB,
TextCB tc = new TextCB("Member Details");
tc.setStyle("<B><I><SPAN STYLE=\"Font-Size : 14pt\"><FONT COLOR=\"red\"
FACE=\"Times NewRoman\">$$$</FONT></SPAN></I></B>");
the $$$
in the above method is replaced by the String passed in the constructor("Member
Details") of the TextCB
tab.setTableHeader(tc);
similarly
for Column Headers,
String
tc3 ="<B><I><SPAN STYLE=\"Font-Size : 14pt\"><FONT COLOR=\"black\"
FACE=\"Brush Script MT\">Occupation</FONT></SPAN></I></B>";
TextCB
tc1 = new TextCB("Name");
TextCB
tc2 = new TextCB("Address","<B><I><SPAN STYLE=\"Font-Size : 14pt\"><FONT
COLOR=\"black\" FACE=\"Brush Script MT\">$$$ </FONT></SPAN></I></B>");
tc1.setStyle(""<B><I><SPAN
STYLE=\"Font-Size : 14pt\"><FONT COLOR=\"black\" FACE=\"Brush Script
MT\">$$$</FONT></SPAN></I></B>");
now,pass
these three objects tc1,tc2,tc3 in vals[] arrays and set it to the Table.
Object vals []= { tc1,tc2,tc3,"Jack","Down
Town","Doctor","Jill","Lake Side","Professor","Bill","High Street","Engineer"};
The Table
will look like this
MEMBER
DETAILS |
Name
|
Address
|
Occupation
|
Jack |
Down Town |
Doctor |
Jill |
Lake Side |
Professor |
Bill |
High Street |
Engineer |
Setting Table Width and Borders
Set the Width,Border and other
Table Styles using setTableStyle(String style)
tab.setTableStyle("<TABLE BORDER=\"0\" WIDTH=\"50%\">");
Member Details |
Name
|
Address
|
Occupation
|
Jack |
Down
Town |
Doctor |
Jill |
Lake
Side |
Professor |
Bill |
High
Street |
Engineer |
Table containing Images and
other ElanBean components
You can set Image or any ElanBean
components to the cells of the Table( see the example)
DropDownListCB dl =new DropDownListCB();
String ListItems []={"Jack","Jill","Bill"};
dl.setValue(ListItems);
ImageCB im=new ImageCB("file:///C:/pure_java_logo.gif",50,50);
//Click on the link below to see how to create the Scroller ElanBean.
ScrollCB ScrollObj = new ScrollCB(array-of-components-to-scroll[]);
DropDownListCB and ImageCB
are two ElanBean components for Dropdownlist box and Image respectively.Add
these two object into the array which you are using to set the cell.
Object vals []= {"Name","Address","Occupation",dl,"Down
Town","Doctor","Jill",ScrollObj,im,"Bill","High
Street","Engineer"};
Member Details |
Name
|
Address
|
Occupation
|
|
Down
Town |
Doctor |
Jill |
|
|
Bill |
High
Street |
Engineer |
This is not the end, you are
provided with all options that are available in the HTML for this Table.
|