Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing: How to disable doubleBuffering on Graphics2D?

 
Tom Rodrigo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is more if an AWT/Swing question than IO, so I'll send the question there.
Dave
 
Tom Rodrigo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
Tom Rodrigo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic