• 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

Accessing Swing widgets while double buffering

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic