• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Swing widgets while double buffering

 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Camick
Ranch Hand
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you override paintComponent instead of paint then it will first paint the component itself, then the children (which include the JCheckBox).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic