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 ]
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...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Dec 07, 2001
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
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...