• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

print the entire swing screen

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Abhijeet Vaidya
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I am going to test your electrical conductivity with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic