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
|