Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Java Printing

Thread view: 
Joah Senegal - 12 Dec 2005 13:28 GMT
Hello all,

I;m trying to do a printjob in java. But there is somthing I do not
understand.

I can;t use the Printable function. I;m using Jbuilding According to
JBuilder this function exists. When I'm trying to compile my project I'll
get the following error:

"Application1.java": cannot resolve symbol: method setPrintable
(printtest.Button1Handler,java.awt.print.PageFormat)in class
java.awt.print.PrinterJob at line 57, column 14

This is my source:
   class Button1Handler
       implements ActionListener {
     public void actionPerformed(ActionEvent e) {
       PrinterJob pjob = PrinterJob.getPrinterJob();
       PageFormat pf = pjob.defaultPage();
       pjob.setPrintable(this,pf);

       try {
           if (pjob.printDialog()) {
               pjob.print();
           }
       } catch (PrinterException s) {
       }

     }
   }

Does anyone have a solution for this problem?
globe_sa - 12 Dec 2005 14:22 GMT
pjob.setPrintable(this,pf); - 'this' (printtest.Button1Handler) is not
a Printable as spesified by PrinterJob ...
BartCr - 12 Dec 2005 14:32 GMT
I'm assuming this is an innerclass in a gui class (extendsing
java.awt.Component), you need something like this:

   class Button1Handler implements ActionListener {

       public void actionPerformed(ActionEvent e) {
           PrinterJob pjob = PrinterJob.getPrinterJob();
           final PageFormat pf = pjob.defaultPage();
           pjob.setPrintable(new Printable() {
               public int print(Graphics g, PageFormat pageFormat, int
pageIndex) {
                   if (pageIndex > 0) {
                       return (NO_SUCH_PAGE);
                   } else {
                       Graphics2D g2d = (Graphics2D) g;
                       g2d.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
                       // Turn off double buffering
                       componentToBePrinted.paint(g2d);
                       // Turn double buffering back on
                       return (PAGE_EXISTS);
                   }
               }
           }, pf);

           try {
               if (pjob.printDialog()) {
                   pjob.print();
               }
           } catch (PrinterException s) {
           }
       }
   }

But as said, I'm making assumptions here, so no idea if this will solve
your problem.

Bart
Joah Senegal - 12 Dec 2005 15:00 GMT
well,

Thanks for your reply. I'll explain a little bit more what I;m trying to do.
I'm drawing a graphic on a panel. I want to print that graphic.

But I;m going to get crazy in here. nothing works :(:(:(

> Hello all,
>
[quoted text clipped - 28 lines]
>
> Does anyone have a solution for this problem?
Oliver Wong - 12 Dec 2005 21:06 GMT
> Hello all,
>
[quoted text clipped - 28 lines]
>
> Does anyone have a solution for this problem?

   The method "setPrintable" expects as its first argument, a Printable,
and, as its second method, a PageFormat. Your second format is a PageFormat
so that's okay, but your first argument is a Button1Handler, not a
Printable. That's what the compiler is complaining about.

   You could make Button1Handler implement Printable, but I get the feeling
that you actually meant to pass in something other than "this".

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.