wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Printing a JPanel to the printer... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing a JPanel to the printer..." Watch "Printing a JPanel to the printer..." New topic
Author

Printing a JPanel to the printer...

Joe Vahabzadeh
Ranch Hand

Joined: Jan 05, 2005
Posts: 140
All,

I wasn't sure if this was the appropriate forum for this, but I couldn't find one specific to printing to a printer.

I'm trying to send a JPanel to a printer.

I have the following routine which seems to more or less work, but exhibits a few problems. I've gotten most of the code off a website.


Now I get things to print by calling the printComponent method and passing in my JPanel. No problem, the scaling and all works.

However, whether I scale things to fit the page, or remove that code, I get some strange behavior.

The JPanel has a few JLabels scattered about in a GridBagLayoutt, in three general columns.

However, I've noticed that *some* of the items in each column get truncated and have "..." tacked onto the end. But it doesn't do this to just the longest items, it also does it to shorter items, even if a longer one in the same column was NOT truncated in this manner.

So, what I'll have in one column is something like:

A long line that's been truncated...
a short line, no problem
a short line truncated...
longer than above, not truncated

On screen, it's normal. Printed out, those weird truncations occur.

Why is this happening? There's plenty of room, and each of the lines that are getting truncated could easily be 1-1/2 times their length without the danger of bumping into the next column.

Is there any way to for me to force it to print the entire line in each case rather than cutting things off the way it's doing?

Thanks!


EDIT: Another problem I'd like to solve is that, the JPanel is gray with black text. I'm fine with that onscreen, but when it prints out, it prints a gray rectangle for the panel, with black text on it. Is there any way I can have this not print out the background as well (ie: treat background as white and only print the text that's on the JPanel?)

[ February 04, 2005: Message edited by: Joe Vahabzadeh ]
[ February 04, 2005: Message edited by: Joe Vahabzadeh ]
 
Consider Paul's rocket mass heater.
 
subject: Printing a JPanel to the printer...
 
Similar Threads
Printing TextArea which span more than 1 page
Printing
java applet print
Font Problem in Java Print API
Printing Problem to print header