GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Images" Watch "Images" New topic
Author

Images

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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 ]
dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
By the way, nice applet!


Dave Taubler<br />Specializing in <a href="http://taubler.com/articles/" target="_blank" rel="nofollow">Java and Web Development</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Images