The Artima Developer Community
Sponsored Link

Java Answers Forum
Printing problem can anyone help please

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
laurence

Posts: 1
Nickname: laurence10
Registered: Mar, 2003

Printing problem can anyone help please Posted: Mar 11, 2003 12:47 PM
Reply to this message Reply
Advertisement
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;

public printUtility(Graphics g, Component textArea)
{
printJob = PrinterJob.getPrinterJob();
printGraphics=g;
componentToBePrinted=textArea;
printJob.setPrintable(this);

if (printJob.printDialog())
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}

//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
}
}


Topic: how to implement a search engine ? Previous Topic   Next Topic Topic: creating a web site

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use