wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes printing of scrorableresultsetable. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "printing of scrorableresultsetable." Watch "printing of scrorableresultsetable." New topic
Author

printing of scrorableresultsetable.

sachin komurlekar
Greenhorn

Joined: May 09, 2001
Posts: 14
i have a table which is having around 400 rows i want to print all these rows(hidden also)as normal printcomponent will print only those rows which are seen.
please help me with a code.
also how can i define the size of the component to be printed on the paper so that my printing will come exactly on the paper.
Ravi Kumarasinghe
Greenhorn

Joined: Jun 07, 2001
Posts: 6
Originally posted by sachin komurlekar:
i have a table which is having around 400 rows i want to print all these rows(hidden also)as normal printcomponent will print only those rows which are seen.
please help me with a code.
also how can i define the size of the component to be printed on the paper so that my printing will come exactly on the paper.

Tty this:
This prints a JTable callerd tableView
public int print(Graphics g, PageFormat pageFormat,
int pageIndex) throws PrinterException {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.black);
int fontHeight=g2.getFontMetrics().getHeight();
int fontDesent=g2.getFontMetrics().getDescent();
//leave room for page number
double pageHeight = pageFormat.getImageableHeight()-fontHeight;
double pageWidth = pageFormat.getImageableWidth();
double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
double scale = 1;
if (tableWidth >= pageWidth) {
scale = pageWidth / tableWidth;
}
double headerHeightOnPage=
tableView.getTableHeader().getHeight()*scale;
double tableWidthOnPage=tableWidth*scale;
double oneRowHeight=(tableView.getRowHeight()+
tableView.getRowMargin())*scale;
int numRowsOnAPage=
(int)((pageHeight-headerHeightOnPage)/oneRowHeight);
double pageHeightForTable=oneRowHeight*numRowsOnAPage;
int totalNumPages= (int)Math.ceil((
(double)tableView.getRowCount())/numRowsOnAPage);
if(pageIndex>=totalNumPages) {
return NO_SUCH_PAGE;
}
g2.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
g2.drawString("Page: "+(pageIndex+1),(int)pageWidth/2-35,
(int)(pageHeight+fontHeight-fontDesent));//bottom center
g2.translate(0f,headerHeightOnPage);
g2.translate(0f,-pageIndex*pageHeightForTable);
//If this piece of the table is smaller than the size available,
//clip to the appropriate bounds.
if (pageIndex + 1 == totalNumPages) {
int lastRowPrinted = numRowsOnAPage * pageIndex;
int numRowsLeft = tableView.getRowCount() - lastRowPrinted;
g2.setClip(0, (int)(pageHeightForTable * pageIndex),
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(oneRowHeight * numRowsLeft));
}
//else clip to the entire area available.
else{
g2.setClip(0, (int)(pageHeightForTable*pageIndex),
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(pageHeightForTable));
}
g2.scale(scale,scale);
tableView.paint(g2);
g2.scale(1/scale,1/scale);
g2.translate(0f,pageIndex*pageHeightForTable);
g2.translate(0f, -headerHeightOnPage);
g2.setClip(0, 0,(int) Math.ceil(tableWidthOnPage),
(int)Math.ceil(headerHeightOnPage));
g2.scale(scale,scale);
tableView.getTableHeader().paint(g2);//paint header at top
return Printable.PAGE_EXISTS;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printing of scrorableresultsetable.
 
Similar Threads
Problem in printing a JTable
printing module
priniting module
printing of scrorableresultsetable.
priniting module