Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Images

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I was wondering if it was possible to get an Image/BufferedImage, on to a JPanel, similar to when you do...



I know I can simply do a drawImage(...) inside the paintComponent(...) method, but I am having to repaint the screen many times with several small images, and I wanted to do it so the background does not have to be continuously repainted.

Is this possible? Thanks
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No matter what you do - the background is going to be continuously repainted... all that setBackground(Color background) does is set some variable in the JComponent superclass that gets used in JComponent.paintComponent() as:


If you're worried about re-doing stuff in the paint method that you don't need to re-do every time (like scaling, rotating, modifying an image, string, geometric shape, etc.) then you can create a BufferedImage, paint to the BufferedImage's Graphics, and then inside your paintComponent() method, just paint the BufferedImage only.

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, thats kind of the same thing I was trying today, double buffering I think its called.

I still have a problem though with my applet.
Rubiks Cube

I'm using double buffering (painting to an Image, then displaying image),
but I'm still getting a little bit of black flickering that can be seen when the cube is twisted(by pulling on a non-center face), the black flickering can usually be seen where two small faces join, whilst being twisted.

I have found, that on a Mac computer this flickering is really bad, but hardly noticeable when using windows.
I assumed double buffering would fix this, but it hasn't, any ideas?

Thanks
[ April 03, 2007: Message edited by: colin shuker ]
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, nice applet!
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic