I solved the problem by painting the whole table to a printer page, resizing it accordingly etc. As printing is in fact painting just to a different receiver.
@Saher please check my answer to other question where I present links which were useful for me in understanding how the API works/can be applied.
EDIT:
Please do check the tutorials especially no. 2.
The way I am doing it is that I have a MyPrintUtilityclass which implements Printable interface.
Its constructor takes a component I want to print. When it takes the component it calculates how many pages it will take and stores page end points. Then I have a method I call for it that initailizes the print dialog.
public void print()
{
PrinterJob printJob = PrinterJob.getPrinterJob();
if(printJobName != null)
printJob.setJobName(printJobName);
printJob.setPrintable(this);
if(printJob.printDialog())
try
{
//for faster printing, turn off double buffering
disableDoubleBuffering(componentToPrint);
System.out.println("Calling PrintJob.print()");
printJob.print(new HashPrintRequestAttributeSet());
System.out.println("End PrintJob.print()");
}catch(PrinterException pe)
{
System.out.println("Error printing: " + pe);
}finally//whatever happend (exception or not) turn back on the double buffering
{
enableDoubleBuffering(componentToPrint);
}
}
In the public int print(Graphics g, PageFormat pf, int pageIndex)
method of the Printable interface I translate the graphic accordingly clipping the table for each page.
More resources to check:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/PrintinJavaMultipage.htm --- printing on many pages
http://download.oracle.com/javase/tutorial/2d/printing/gui.html --- printing GUI components.
http://www.sideofsoftware.com/print_preview_tutorial.htm --- print preview tutorial
http://www.java-tips.org/java-se-tips/java.awt.print/print-the-text-file-and-print-preview-them.html --- a fantastic example of how to preview and print text files.
EDIT2:
You must seriously read this one. Here author explains how splitting on many pages works and how to translate the graphics and move the clip etc.