File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Accessing Swing widgets while double buffering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Accessing Swing widgets while double buffering" Watch "Accessing Swing widgets while double buffering" New topic
Author

Accessing Swing widgets while double buffering

Matthew Snow
Ranch Hand

Joined: May 02, 2007
Posts: 80
I'm double buffering to reduce screen flicker which basically means that instead of calling repaint(), I'm drawing directly to an Image object and then call JPanel.getGraphics().drawImage(masterImage); to refresh the display. I would like to make use of Swing's GUI widgets, like JCheckBox. Is there a way I can extract a widgets display as an Image so I can just throw it into my master image using it's Graphics.drawImage() method?


When you break the big rules, you get a lot of little rules.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2092
    
    7
I'm double buffering


Swing is double buffered by default. I'm not sure what your code does for you.

I would like to make use of Swing's GUI widgets, like JCheckBox.


Painting an image of a check box will not make it behave like a check box.

Is there a way I can extract a widgets display as an Image


Screen Image show one way.
Matthew Snow
Ranch Hand

Joined: May 02, 2007
Posts: 80
The Swing widgets themselves are double buffered. My display has a bunch of custom graphics and some animation, which causes a lot of screen flicker when animating. That's why I'm drawing all my stuff to a single Image object and sending it to the screen just once.

Now, you are right in that even if I did extract the widget's image and threw it onto this Image object, I would not be able to use it since the actual widget would be underneath this Image object I'm throwing up. Is it possible for me to tell the JCheckBox to always remain on top when I add it to the JPanel so when I throw this Image up it will be under the JCheckBox? Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

If you override paintComponent instead of paint then it will first paint the component itself, then the children (which include the JCheckBox).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Accessing Swing widgets while double buffering
 
Similar Threads
how to get rid off flickering in JOptionPane dialog
sending a response
Is this possible to do?
Double buffering delivered widgets
Creating Java applet