Have been trying to get this to work for way too long now is there anyone out there who can help me to print one tiny little text area...please
// this requests new print utility if (event.getSource() == print) { printMenu = new printUtility(this.getGraphics(),theResult); } if (event.getSource() == newProfessional)
//Here is print utility which is starting up the //printer...but printing nothing; please help me understand //y
import java.awt.*; import java.awt.print.*;
public class printUtility implements Printable { private Component componentToBePrinted; //holds the component for printing private PrinterJob printJob; Graphics printGraphics;
//print method of printable interface with arguments: //graphics(the context that is used to write to the printer) //pageformat(provides details of the page size, position & size of the printable area on screen & orientation) //pageindex(carries an index value for the page 1stpage = 0, 2nd = 1 etc) public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return NO_SUCH_PAGE; //only want 2 print 1 page so if more return } //NO_SUCH_PAGE to stop printing else { Graphics2D g2d = (Graphics2D) g; g2d.setPaint(Color.black); g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); //translate method moves the user componentToBePrinted.paint(g2d); //coordinates so that 0,0 is return PAGE_EXISTS; //positioned @ the top left corner } //of the printable page } }