Help with printing problem

Below is the code I have for my print class. It may be all screwed up, I tried as best I could to put something together that would function. I want a generic print class that can print whatever I send it, like an entire frame or the contents of a text box. This code works somewhat. When I print a JFrame it does not print the frame itself but it does print it's contents. But I want the whole frame with menu, contents, title, etc. Also I want it to print things to scale so they don't come out all huge, and also so stuff that is bigger will scale down to fit the page. Any help would be greatly appreciated.

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.print.*;

import javax.swing.*;

import javax.swing.event.*;

publicclass PrintUtilimplements Printable, Pageable{

private ComponentitemToPrint;

private PageFormat defaultPageFormat =new PageFormat();

publicstaticvoid printComponent(Component c){

new PrintUtil(c).print();

}

public PrintUtil(Component c){

itemToPrint = c;

}

publicvoid print(){

PrinterJob pj = PrinterJob.getPrinterJob();

pj.setPageable(this);

pj.setJobName("Printing");

if (pj.printDialog())

try{

pj.print();

}catch(PrinterException pe){

System.out.println("Error printing: " + pe);

}

}

publicint print(Graphics g, PageFormat pageFormat,int pageIndex){

Graphics2D g2 = (Graphics2D)g;

int fontHeight = g2.getFontMetrics().getHeight();

int fontDesent = g2.getFontMetrics().getDescent();

double pageHeight = pageFormat.getImageableHeight() - fontHeight;

double pageWidth = pageFormat.getImageableWidth();

double widthScale = .75;

double heightScale = .75;

int totalPages = (int)Math.ceil((heightScale * itemHeight)/ pageHeight);

if (pageIndex >= totalPages){

return(NO_SUCH_PAGE);

}

g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

g2.scale(widthScale, heightScale);

disableDoubleBuffering(itemToPrint);

itemToPrint.paintAll(g2);

enableDoubleBuffering(itemToPrint);

return(PAGE_EXISTS);

}

publicint getNumberOfPages(){

return(1);

}

public PageFormat getPageFormat(int pageIndex)throws IndexOutOfBoundsException{

if (pageIndex >= getNumberOfPages()){

thrownew IndexOutOfBoundsException("Page " + pageIndex +" does not exist !");

}

else{

return(defaultPageFormat);

}

}

public Printable getPrintable(int pageIndex)throws IndexOutOfBoundsException{

if (pageIndex >= getNumberOfPages()){

thrownew IndexOutOfBoundsException("Page " + pageIndex +" does not exist !");

}

else{

return(this);

}

}

publicstaticvoid disableDoubleBuffering(Component c){

RepaintManager currentManager = RepaintManager.currentManager(c);

currentManager.setDoubleBufferingEnabled(false);

}

publicstaticvoid enableDoubleBuffering(Component c){

RepaintManager currentManager = RepaintManager.currentManager(c);

currentManager.setDoubleBufferingEnabled(true);

}

}

[6505 byte] By [adtarr] at [2007-9-27 14:31:17]
# 1
**BUMP**
adtarr at 2007-7-5 22:30:42 > top of Java-index,Archived Forums,Java Programming...
# 2
Read the API
adtxs2 at 2007-7-5 22:30:42 > top of Java-index,Archived Forums,Java Programming...