• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Double buffering delivered widgets

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic