• Post Reply Bookmark Topic Watch Topic
  • New Topic

Double buffering delivered widgets  RSS feed

 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm doing is double buffering my GUI app, basically rather than calling JPanel.repaint() I've created a BufferedImage and am drawing directly to it and then just calling Graphics.drawImage(Image, int, int, ImageObserver) my JPanel's Graphics object. This of course prevents me from simply adding the delivered swing widgets to my JPanel. Is there a way I can extract the Image of a widget so I can just add it to my BufferedImage? Calling JComponent.creatImage() on these widgets only seems to give me an empty image object.
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rather than calling JPanel.repaint() I've created a BufferedImage and am drawing directly to it and then just calling Graphics.drawImage(Image, int, int, ImageObserver)


I've never seen that before and fail to understand the reasoning for that. All painting should be done from within the paintComponent() method and not outside it using a Graphics object.

Is there a way I can extract the Image of a widget


A Screen Image might be what you are looking for.
 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason why I'm doing it is avoid IO slow down. It takes a while for the JComponent to send updated images to the screen one widget at a time. With the BufferedImage, I update only what I want and all I want all at once with just one call to the screen.

This will explain it better than I can: http://fivedots.coe.psu.ac.th/~ad/jg/ch1/ch1.pdf
 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob, checked out your ScreemImage code and saw it was calling Component.paint(Graphics). Using my BufferedImage's Graphics object as the parameter is just what I wanted.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!