aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes print the entire swing screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "print the entire swing screen " Watch "print the entire swing screen " New topic
Author

print the entire swing screen

Abhijeet Vaidya
Greenhorn

Joined: Apr 16, 2007
Posts: 20
Hi,

I want to print the entire swing screen (with content) using Java print API. How should I go about it? I tried calling print()/printAll() method on JFrame, but it's creating a problem in component alignment on the paper. Like only half JTable is getting printed etc. Do I need to override paintComponent(Graphics g) before printing the each component or is there any better way of doing it?

Thanks in advance.
Abhijeet
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

The problem is that the component tries to paint itself on the first page only. The parts that do not fit just get ignored.

You should create a Printable (java.awt.print) or Doc (javax.print) that will make sure your component is spread over multiple pages.

Fortunately I already wrote something like that once. Here's the print method:

The horizontal field determines whether to print the pages left-to-right first or top-to-bottom first.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhijeet Vaidya
Greenhorn

Joined: Apr 16, 2007
Posts: 20
Hi Rob,

Thanks for the code, but still things are not working for me. My scenario is like this: I have a swing screen with one JTable in the middle of the screen and a logo image below the JTable resulting in 2 pages (print wise). I am new to swing/printing, so cold you please help me with the multiple page thing? I am not getting how to use Doc or Book as you suggested. I am passing my entire JFrame as component to print(). Also as per my understanding graphics.translate() should rearrange the table according to page coordinates, but even it's not happening that way. Let me know if you want me to send a screen shot of the page am trying to print.

Thanks a lot!!
Abhijeet
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Well I'm not using Doc or Book but just Printable. I still haven't explored the javax.print package really well yet, so far my printing is limited to java.awt.print.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: print the entire swing screen