File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Printing: How to disable doubleBuffering on Graphics2D? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing: How to disable doubleBuffering on Graphics2D?" Watch "Printing: How to disable doubleBuffering on Graphics2D?" New topic
Author

Printing: How to disable doubleBuffering on Graphics2D?

Tom Rodrigo
Greenhorn

Joined: Dec 07, 2001
Posts: 26
Hello all,
I want to print a JPanel jp1 and some graphics (rectangle, rectangle2D and drawn Strings) on the same paper.
For some special reasons I cannot add the graphics and the panel jp1 to another JPanel and print this other panel on my printer. So I need to create a printerJob() for my JPanel jp1 and draw the graphics on the jp1 graphics2D in the print()-method.
I have tested this out and everything works fine, but my printer needs a lot of time before printing. I suppose this is because of doubleBuffering, as when I comment out my graphics, my printer prints immediately [for jp1 doubleBuffering is turned off].
Now, how can I disable doubleBuffering for my graphics?
Here is the print()- method for my JPanel jp1:

To make it clear: I must draw my graphics in the print()-method. I cannot add them to a panel. And I need to use Graphics2D. I don't know exactly what doubleBuffering is, maybe it's the wrong way trying to disable it on my graphics, but my printer needs a lot of time before starting to print.
I have no idea how to solve this.
Any comments on this?
Thanks in advance !
Tom
[ August 22, 2002: Message edited by: Tom Rodrigo ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This is more if an AWT/Swing question than IO, so I'll send the question there.
Dave
Tom Rodrigo
Greenhorn

Joined: Dec 07, 2001
Posts: 26
No reply ??
I'm trying to solve this problem for hours and hours, but I still have no clue about it.
There must be a way to do it.
Come on guys, any help is appreciated.
Thanks in advance!
Tom
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I messed around some with the printing API and found that the double buffering problem by painting the component to a BufferedImage, then painting the BufferedImage in the print() method... I didn't see any slowdown in either case, though... try my test code and see if it solves your problem...



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tom Rodrigo
Greenhorn

Joined: Dec 07, 2001
Posts: 26
Hello Nate,
thank you very much for your response!
I tried your PrintTest() and yes, there is no slowdown, but it makes no difference if BufferedImage is used or not (at least to my printer...)
I also tried BufferedImage on my code, but the problem stays the same.
This seems to be hopeless...
Nevertheless I would like to thank you for giving me some new input and spending your time on my prob.
I'm glad to have a place like Big Moose Saloon!
Tom
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Hmmm... what kind of output are you getting from your printer? When I was messing around with my example I originally got something that looked more like a graphics buffer (had graphics in various states of completion), a big gray block the size of my panel, and then finally I figured out how to print out the the "real" graphics. What is the printer printing when you run my test program?

If you want you can post / email me your code and I can take a look at it...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing: How to disable doubleBuffering on Graphics2D?