users
[Top] [All Lists]

Re: [cinjug-users] printing in Java

To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] printing in Java
From: Eric Galluzzo <egalluzzo@xxxxxxxxxxxxxxx>
Date: Fri, 12 Nov 2004 11:18:10 -0500
Delivered-to: mailing list users@cinjug.org
In-reply-to: <20041112152306.19349.qmail@web50105.mail.yahoo.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <20041112152306.19349.qmail@web50105.mail.yahoo.com>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7b) Gecko/20040421
Jason Kretzer wrote:

I saw this thread on another JUG and decided to post
it here as the other JUG is still debating it.

Lets say you have a very simple Notepad style editor
written in Java, like the Notepad that comes with SDK.
How would one add functionality to allow the app to
print? For both a networked and connected printer?


Look into writing a class (perhaps just your Notepad component itself) that implements java.awt.print.Printable or java.awt.print.Pageable, depending on whether you want control over the pagination or not. Then, in order to actually print it, do something like this:

Pageable pageable = ...; // or Printable if you want
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable( pageable ); // or Printable if you want
job.setName( "My Application - My Document Name" ); // or whatever
job.print();

There's even a print preview dialog that we made and stuck in EII Commons (http://www.einnovation.com/projects/eiicommons/) if you want to use it. I think it requires a Pageable, not a Printable.

   - Eric


<Prev in Thread] Current Thread [Next in Thread>