This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Double buffering delivered widgets

 
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.
 
Rancher
Posts: 3111
26
  • 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.
 
I don't like that guy. The tiny ad agrees with me.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!