Cricinfo Live Scores

Tuesday, January 29, 2008

Java print API for splitted JTable

In this article i am posting a Java API which is capable of printing JTable by splitting
the columns according to the Page Format of the printing file.

The example creates a Table Model from a set of data. The number of columns in this
case is more to fit in one page. So, the solution is provided here to split the table columns
and print them as such this.

Full Page
--------------------------
--------------------------
--------------------------
-----------1--------------
--------------------------

Split Page 1
---------
---------
---------
---1-2---
---------

Split Page 2
---------
---------
---------
---1-2---
---------

Split Page 3
---------
---------
---------
---1-3---
---------

The solution is implemented as applet. The solution goes in this way First getPageInfo()
function derives the page information. That is, the number of splits should be made depending
upon the length of the table column and page format. This function makes a temporary data
array subTableSplit which describes the page left and page right for each split of the page
through out the JTable.

Next that particular part pageWidth = pageRight-pageLeft is printed.

The complete code is available in the following link.


http://www.mediafire.com/?excw0rz0s7c

Author:
-----------------------
Kazi Masudul Alam
Software Engineer